1.0.0 • Published 7 years ago

bodyparser-json-error v1.0.0

Weekly downloads
60
License
MIT
Repository
github
Last release
7 years ago

bodyparser-json-error

Beautify body parser JSON syntax error

Build Status npm version

Installation

npm install bodyparser-json-error --save

Usage

var express = require('express');
var bodyParser = require('body-parser');
var bodyParserError = require('bodyparser-json-error');

var app = express();

app.use(bodyParser.urlencoded({
    extended: true
}));
app.use(bodyParser.json());

// Beautify body parser json syntax error
app.use(bodyParserError.beautify());

Middleware Options

You can optionally set the status code and response for the body parser syntax error.

app.use(bodyParserError.beautify({status: 500 , res: {msg: 'You sent a bad JSON !'}}));

The output:

HTTP Status Code: 500

{
  "msg": "You sent a bad JSON !"
}

Options

  • status: The response status code. Default: 400
  • res: The response body. Default: {msg: 'Invalid JSON'}

Tests

To run the test suite, first install the dependencies, then run npm test:

$ npm install
$ npm test

License

MIT License