Hey ! I discovered when updating a record using RecordUpdater that when I’m violating a primary key, the recordUpdater throws a ErrorHTTP422, with a message “Validation error” but no detail is given about the error. I need to manually go to resource-updater and put a console.log of the error here to understand that it is PK violation.
Is it an expected behavior of the library that no details about the error is given ?
Hi @Simon_BRAMI1
please can you share with us the version of forest-express-sequelize did you use ?
And the sample of code who are using RecordUpdater.
Hi Arnaud, I’m using “^9.2.6” version
The sample of code is a bit long but here’s a simplified version:
//....
const recordUpdater = new RecordUpdater(CatalogueItem, user, defaultQuery);
const recordToUpdate = await recordUpdater.deserialize(body);
try {
const record = await recordUpdater.update(recordToUpdate, catalogueItemId);
let recordSerialized = await recordUpdater.serialize(record);
response.status(200).send(recordSerialized);
}
catch (e) {
next(e);
}
There’s nothing crazy about it, the issue is only the error message being too simple and not explicit about the PK violation.
pretty strange actually when i do a thing similar i ged a “nice error”
In my case I’m violating a composite PK composed by 3 columns. Maybe that’s why ?
Here is what my console.log was printing:
UniqueConstraintError [SequelizeUniqueConstraintError]: Validation error
at Query.formatError (/Users/simonbrami/rendu/edumiam/forest_backend/node_modules/sequelize/lib/dialects/postgres/query.js:312:18)
at /Users/simonbrami/rendu/edumiam/forest_backend/node_modules/sequelize/lib/dialects/postgres/query.js:71:18
From previous event:
at Query.run (/Users/simonbrami/rendu/edumiam/forest_backend/node_modules/sequelize/lib/dialects/postgres/query.js:64:23)
at /Users/simonbrami/rendu/edumiam/forest_backend/node_modules/sequelize/lib/sequelize.js:641:29
From previous event:
at /Users/simonbrami/rendu/edumiam/forest_backend/node_modules/sequelize/lib/sequelize.js:641:12
From previous event:
at /Users/simonbrami/rendu/edumiam/forest_backend/node_modules/sequelize/lib/sequelize.js:637:10
at /Users/simonbrami/rendu/edumiam/forest_backend/node_modules/sequelize/node_modules/retry-as-promised/index.js:70:21
at new Promise (<anonymous>)
at retryAsPromised (/Users/simonbrami/rendu/edumiam/forest_backend/node_modules/sequelize/node_modules/retry-as-promised/index.js:60:10)
at /Users/simonbrami/rendu/edumiam/forest_backend/node_modules/sequelize/lib/sequelize.js:627:30
From previous event:
at Sequelize.query (/Users/simonbrami/rendu/edumiam/forest_backend/node_modules/sequelize/lib/sequelize.js:576:23)
at QueryInterface.update (/Users/simonbrami/rendu/edumiam/forest_backend/node_modules/sequelize/lib/query-interface.js:1012:27)
at /Users/simonbrami/rendu/edumiam/forest_backend/node_modules/sequelize/lib/model.js:3985:52
at processImmediate (internal/timers.js:464:21)
From previous event:
at self.save (/Users/simonbrami/rendu/edumiam/forest_backend/node_modules/sequelize/lib/model.js:3962:8)
at ResourceUpdater.perform (/Users/simonbrami/rendu/edumiam/forest_backend/node_modules/forest-express-sequelize/dist/services/resource-updater.js:32:22)
at async updateCatalogueItem (/Users/simonbrami/rendu/edumiam/forest_backend/controllers/catalogueItem.js:435:22)
at async /Users/simonbrami/rendu/edumiam/forest_backend/routes/catalogue-item.js:111:32 {
errors: [
ValidationErrorItem {
message: 'start_opco must be unique',
type: 'unique violation',
path: 'start_opco',
value: '2022-06-25',
origin: 'DB',
instance: [catalogueItem],
validatorKey: 'not_unique',
validatorName: null,
validatorArgs: []
},
ValidationErrorItem {
message: 'learner_id must be unique',
type: 'unique violation',
path: 'learner_id',
value: '5843',
origin: 'DB',
instance: [catalogueItem],
validatorKey: 'not_unique',
validatorName: null,
validatorArgs: []
},
ValidationErrorItem {
message: 'catalogue_entity_id must be unique',
type: 'unique violation',
path: 'catalogue_entity_id',
value: '54',
origin: 'DB',
instance: [catalogueItem],
validatorKey: 'not_unique',
validatorName: null,
validatorArgs: []
}
],
fields: {
start_opco: '2022-06-25',
learner_id: '5843',
catalogue_entity_id: '54'
},
.......
Maybe Sequelize doesn’t render properly this kind of error.
As we take only the message for display purpose, that’s why the error look’s bad.
Like we see it, is working nicely on “simple” constraint error.
Let me know if i can help more.
Ok, thanks anyways for helping!