1.1.0 • Published 5 years ago

http-json-error-handler v1.1.0

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

http-json-error-handler

npm Build Status GitHub npm Coverage Status

Installation

You can download http-json-error-handler from NPM

$ npm install http-json-error-handler --save

then in your project require http-json-error-handler

const errorHandler = require('http-json-error-handler');

or GitHub

$ git clone https://github.com/lfurnielis/http-json-error-handler.git

Guide

const errorHandler =  require('http-json-error-handler');
const express = require('express');

const app = express();

// Your defined middlewares
...
...

// Your defined routes
app.get('/foo', (req, res, next) => {
    const error = new Error('Missing field(s): foo');
    error.status = 400;
    error.code = 10401;
    next(error);
});

// HTTP error handler
app.use(errorHandler({
	stderr: true // Default: false
}));

Options

{
  stderr: false // Log errors using console.error(), Default: false
  stackerr: false // Log error.stack using console.debug() only for statusCode >= 500, Default: false
}

Definition of a "Error"

The error could contain the following fields:

Error KeyPurpose
messageError details.
statusHTTP status code for response. Default: 500 (Internal Server Error).
codeError code. Default: same as "status".

HTTP JSON Error Example

{
  "error": {
    "code": 10401,
    "message": "BAD REQUEST",
    "details": "Missing field(s): foo"
  }
}
1.1.0

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

0.19.3

5 years ago

0.19.2

5 years ago

0.19.1

5 years ago

0.19.0

5 years ago

0.18.6

5 years ago

0.18.5

5 years ago

0.18.4

5 years ago

0.18.3

5 years ago

0.18.1

5 years ago