Feature(s) impacted
Can not show custom error message for status code 500 and 413.
Observed behavior
Whenever unexpected error occurred at server level, we catch it at server and send more meaningful error message to user for Smart Action. But when status of response is 500 or 413, custom message is not displayed, rather generic error is show .i.e. - Unexpected error with action.
But when error code is other than 413, 500. Custom error message is displayed correctly.
Expected behavior
Custom message should be displayed for all error status codes so user will be able to figure out mistakes.
Context
- Project name: Curator
- Team name: Developer
- Environment name: ALL (Staging, Development, Production)
- Agent type & version:
- Package Version: 8.3 (forest-express-sequelize)
- Express Version: 4.17.1
- Sequelize Version: 6.6.5
- Database Dialect: MySql
- Database Version: 5.7.24
Hello @Nilesh_Shirsat,
Thanks for your message. I’ll sync with our product team to know if it is the intended behavior or not.
I say this because 500 error code is by standard Internal Server Error and 500 error code is Entity too large not sure we want you to customize those errors.
We also have the documentation on the subject, so you can easily use another HTTP error (400 so far) when you know the cause of the error (instead of an error 500).
Let me know if it helps.
Best regards,
Morgan
Hi @morganperre,
Any update from product team?
Use case we would like to customise internal server error message so that can be consistent across application in our organisation also if we can help pass error stating rootcause then it will help user avoid mistakes again.
Thanks.
Hey @Nilesh_Shirsat,
It is the intended behavior. Unfortunately, we want to force clients to catch internal error and send a 400 status code with a properly user readable error in order to avoid displaying silly errors to users.
I see your point. In this case I would suggest to add a middleware to the forest routes that responds with 400 status code and the error message.
Middleware
exports.expectedErrorsBusinessMiddleware = function expectedErrorsBusinessMiddleware(error, request, response, next) {
// If you have internal mechanism to throw error that only extend a BaseError class
if (error instanceof BaseError) {
response.status(400).send({ error: error.message });
} else {
// Error that cannot be handled (same behavior as describe it will display Unexpected error with XXX action)
next(error);
}
};
app.js
// Transform expected errors
app.use('/forest', expectedErrorsBusinessMiddleware);
And in the end in the SmartActions definition you just need to call next(error)
when catching an error.
try {
...
// code that can throw internal error
...
} catch (error) {
next(error);
}
Let me know if it helps.
Kind regards,
Morgan