express-json-errors
An error handler for JSON APIs. They follow the general 'spec' outlined here
Example
var express = errorHandler = ; var app = ;app; // An simple example "route" or middlewareapp;
API
By default you have res.error
to use. You can send it Strings, plain Objects, Errors, Arrays (containing any combination of Strings, Objects, or Errors).
// Using stringsapp; // Using Objectsapp; // Using Errorsapp; // Using Arraysapp;
There is also support for express-validator. You can use it like:
app;
Status Codes
The API has a somewhat semantic way of handling errors. If you only have on error, the default error code is 400 unless otherwise specified. So for example:
// A single errorapp; // A single errorapp;
If you have multiple errors (aka an array of errors) the system will default to 400. Then each error object in the response will have it's own status code.
If you use a JS error, the status code will be 500. For example:
// A single errorapp;