Jozef Cipa 808b2a464f
Handle duplicate entry error (#8367)
* Handle duplicate entry error message in bookshelf connector

Signed-off-by: jozefcipa <jozef.cipa@strv.com>

* Handle duplicate error message in mongoose connector

Signed-off-by: jozefcipa <jozef.cipa@strv.com>

* Apply changes from review

* Fix wrapping transactions in bookshelf adapter

* Add missing await to wrapErrors

* Call findOne without this
2021-01-25 14:03:48 +01:00

18 lines
374 B
JavaScript

'use strict';
const isDuplicateEntryError = error => {
return error.code === 11000; // MongoDB code for duplicate key error
};
const handleDatabaseError = error => {
if (isDuplicateEntryError(error)) {
strapi.log.warn('Duplicate entry', error.toString());
throw new Error('Duplicate entry');
}
throw error;
};
module.exports = {
handleDatabaseError,
};