SimpleRest error middleware for converting thrown Meteor.Errors to JSON (according to JSend specification) and sending the response. Based on simple:rest-json-error-handler.
Handle errors from all routes:
JsonRoutes.ErrorMiddleware.use(RestMiddleware.handleErrorAsJsend);Handle errors from one route:
JsonRoutes.ErrorMiddleware.use(
'/handle-error',
RestMiddleware.handleErrorAsJsend
);Response looks like:
{
"status": "error",
"message": "Validation failed",
"code": 400,
"data": {
"error": "validation-error",
"reason": "Validation failed",
"details": [
{
"name": "userId",
"type": "invalid-value"
}
]
}
}