In my app the error ParseError: 101 Object not found
is almost certainly caused by someone not having permissions to view that object due to ACL. So I would like to be able to update this error message (without forking the core) to a custom error message.
I am aware that custom error messages are now possible. However, this would not necessarily be able to be done when the error is likely to be thrown in beforeSave? I don’t want to query for presence first and then update as I am firing this request via the REST API (including the objectId
)
Any ideas?
I’d try to set enableExpressErrorHandler
option to true and add another Express.js middleware after Parse. In this middleware you can verify the error and probably you will be able to send another message. This teste case does not do exactly what you need but it can give you some clue.
1 Like
Thank you! I will have a go.
Bit late here, but here is how I add a custom error message to DUPLICATE VALUE
errors caused by unique indexes:
app.use((err, req, res, next) => {
let httpStatus;
switch (err.code) {
case Parse.Error.INTERNAL_SERVER_ERROR:
httpStatus = 500;
break;
case Parse.Error.OBJECT_NOT_FOUND:
httpStatus = 404;
break;
default:
httpStatus = 400;
}
res.status(httpStatus);
let error = err.message;
if (req.originalUrl.includes('Goal') && err.code === Parse.Error.DUPLICATE_VALUE) {
error = `You have already created a goal with the name ${req.body.name}.`;
}
res.json({ code: err.code, error });
});