simple:rest-json-error-handler

v1.0.1Published 8 years ago

This package has not had recent updates. Please investigate it's current state before committing to using it in your project.

simple:rest-json-error-handler

SimpleRest error middleware for converting thrown Meteor.Errors to JSON and sending the response.

Usage

Handle errors from all routes:

1JsonRoutes.ErrorMiddleware.use(RestMiddleware.handleErrorAsJson);

Handle errors from one route:

1JsonRoutes.ErrorMiddleware.use(
2  '/handle-error',
3  RestMiddleware.handleErrorAsJson
4);

Example

1JsonRoutes.ErrorMiddleware.use(
2  '/handle-error',
3  RestMiddleware.handleErrorAsJson
4);
5
6JsonRoutes.add('get', 'handle-error', function () {
7  var error = new Meteor.Error('not-found', 'Not Found');
8  error.statusCode = 404;
9  throw error;
10});