mirror of
https://github.com/strapi/strapi.git
synced 2025-12-26 14:44:31 +00:00
Mongoose unique index error logs and other index error logs
This commit is contained in:
parent
664491d593
commit
e1a319a25e
@ -8,6 +8,7 @@
|
||||
"type": {
|
||||
"type": "string",
|
||||
"required": true,
|
||||
"unique": true,
|
||||
"configurable": true
|
||||
}
|
||||
}
|
||||
|
||||
@ -272,6 +272,20 @@ module.exports = ({ models, target, plugin = false }, ctx) => {
|
||||
definition.collectionName
|
||||
);
|
||||
|
||||
Model.on('index', error => {
|
||||
if (error) {
|
||||
if (error.code === 11000) {
|
||||
strapi.log.error(
|
||||
`Unique constraint fails, make sure to update your data and restart to apply the unique constraint.\n\t- ${error.message}`
|
||||
);
|
||||
} else {
|
||||
strapi.log.error(
|
||||
`An index error happened, it wasn't applied.\n\t- ${error.message}`
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (!plugin) {
|
||||
global[definition.globalName] = Model;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user