simple:rest-json-error-handler

v1.1.0Published 4 years ago

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

Compatibility

Compatible with Meteor 2.4

This repository provides versions for the package simple:rest-json-error-handler that are compatible with latest Meteor. This is necessary because the author is not maintaining package anymore.

Changes

  • v1.1.0
    • api.versionsFrom on Package.onUse was changed from 1.0 to 2.4.

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});