Hi,
I get a 422 error when posting a new object with an undhandled rejection exception:
How do you debug those unhandled errors ?
Hi,
I get a 422 error when posting a new object with an undhandled rejection exception:
How do you debug those unhandled errors ?
Hi @theo744
A 422 error relates to an invalid request.
Anyway, we should never have unhandled rejection errors.
What were you doing when this error happened?
Hi @Sliman_Medini,
It happens on instruction
recordCreator.create(recordToCreate)
in the post route of an Object. Same error happens when I replace my custom post method with the default one.
Is it possible to get log of those errors to understand what goes wrong with the request? It’s weird because updating the same object works fine
Ok so, we will consider the default one for the moment.
It means, when you create a new record from Forest UI, you face this 422 error?
Does this happen with all your models? If not can you share the structure of the failing model please.
Can you share an HAR with the traffic that cause the problem? (An HAR can be created by right-clicking in the request list of the request tab of the Chrome dev tools)
I need to reproduce the issue to handle it.
Hi,
Yes, it happens when creating new record from UI. I only have this error with customers, my other objects work fine.
Here’s the configuration of my Customer:
const Customer = sequelize.define('customer', {
idCustomer: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
},
idAddress: {
type: DataTypes.INTEGER,
allowNull: true,
defaultValue: null,
validate: {
customValidator(value) {
if((value == null) || (value == 0))
throw new Error("L'adresse doit être renseignée");
}
}
},
email: {
type: DataTypes.STRING,
allowNull: true,
defaultValue: null,
unique: true,
validate: {
isEmail: true,
customValidator(value) {
if(value === null)
throw new Error("L'adresse email doit être renseignée");
}
}
},
passwd: {
type: DataTypes.STRING,
},
secureKey: {
type: DataTypes.STRING,
},
dateAdd: {
type: DataTypes.DATE,
},
dateUpd: {
type: DataTypes.DATE,
},
active: {
type: DataTypes.BOOLEAN,
defaultValue: true
},
deleted: {
type: DataTypes.INTEGER,
},
}
You can find attached my customer.js file and the har of the post request. It seems the error might be relative to the address relationship because if I delete it, I can create the customer just fine.
app.forestadmin.com_Archive [20-08-01 00-10-37].har (10.5 KB)
Hi @theo744,
Following the code of forest-express-sequelize
, it seems like the only way to trigger a 422 from resource-creator.js
is with an invalid model. (This is visible here). I still find this concerning since you should have a valid error message, but I’m currently not able to reproduce
A workaround to debug this would be to add logs inside node_modules/forest-express-sequelize/services/resource-creator.js
, or a debug log of the request body inside the route that fails, just to be sure that your model is valid.
I can see in your code (Not sure that really matters) that customValidator
is using ==
to compare instead of the more usual ===
. I can’t be sure that is the source of the issue, but I would suggest to give this a try.
Sadly, in the provided HAR, I can’t see any HTTP 422
Hi @theo744 ,
Do you still experience this issue ?