custom error handling

Hello I have a question, when I send a post to create a new record and the record already exists (after I set it to be unique) it returns me err 500 does anyone know how to return an error that says it is not possible to insert a duplicate record?

1 Like

Hi @outboxltd

We currently have an open bug report about this, I don’t currently know of a workaround:

https://github.com/strapi/strapi/issues/6915

Hoping for the fixed on the next major release :grin:

any update on this yet?

I believe this should have been fixed in:

Thanks for this,
However when I run a POST using the Strapi API, I get a 500 error response, but on the server I can see its a duplicate entry. So my question really is how can I capture custom errors for cases like this?

How are you triggering the error?

using slug as an uid, linked to a title
if I post to the strapi api with a duplicate slug,
I get a 500 error on client side in the console log,
on the server log I can see its a duplicate error,
and if I do so using the strapi dashboard,
I get the duplicate error which is what I would prefer to show on the front end I’m developing

Is this issue resolved?

I get duplicate record error in strapi console but 500 error is shown on the client.

Has anyone found any work around for the same? Can I catch the error somehow in the controller or service .js files and send an appropriate message back?

1 Like

I ended up to auto-generate the slug instead, giving less possibility for the user to create a duplicate entry.