-
-
Notifications
You must be signed in to change notification settings - Fork 9.2k
Handle duplicate entry error #8367
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle duplicate entry error #8367
Conversation
Codecov Report
@@ Coverage Diff @@
## master #8367 +/- ##
==========================================
- Coverage 34.64% 34.64% -0.01%
==========================================
Files 1308 1308
Lines 14431 14437 +6
Branches 1432 1432
==========================================
+ Hits 5000 5001 +1
- Misses 8517 8522 +5
Partials 914 914
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
Signed-off-by: jozefcipa <jozef.cipa@strv.com>
Signed-off-by: jozefcipa <jozef.cipa@strv.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why the @strapi/documentation got tagged for review, but if it's related to the translations, they look fine to me.
|
Hi ! @jozefcipa this looks really promising :) can you fix the conflicts on your PR ? |
|
@alexandrebodin fixed! |
|
any update for this ? @jozefcipa |
|
@gddid it is ready and waiting for a review. cc: @alexandrebodin |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you compose the function instead of adding a try catch ?
// keep old implementation
const create = () => {}
return {
create: wrapErrors(create),
update: wrapErrors(update)
}
// utils
// keep your impl
const handleError = () => {}
// add a composable function
const wrapErrors = fn => async (...args) => {
try {
return fn(...args)
} catch (error) {
return handleErrors(error)
}
}
What you did will give the right error when using the queries programmaticaly which the wrap-bad-request doesn't do so still worth it :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, Thank you fro this contribution 💯
|
This pull request has been mentioned on Strapi Community Forum. There might be relevant details there: |
|
This pull request has been mentioned on Strapi Community Forum. There might be relevant details there: |

What does it do?
This PR handles duplicate errors occurred on unique columns in the database and shows a user-friendly message, instead of a raw database error.
Before

After

Fixes #6915, #8664