Hi, this is my proposal of error handling in one center place (error handler function). This prevents code repeating issues (DRY) and increase readability and extensibility (Open/Closed principle from SOLID).
Code of async controller should be wrapped by try..catch (err) next(err) because express4 does not support error handling of promises.
Example response:
{
"error": {
"name": "VALIDATION_ERROR",
"message": "You requested data is not valid.",
"details": [
{
"path": "password",
"message": "password is a required field"
}
]
}
}
Hi, this is my proposal of error handling in one center place (error handler function). This prevents code repeating issues (DRY) and increase readability and extensibility (Open/Closed principle from SOLID).
Code of async controller should be wrapped by try..catch (err) next(err) because express4 does not support error handling of promises.
Example response: