bje

bodyparser-json-error

Beautify Express body-parser syntax error

Showing:

Popularity

Downloads/wk

13

GitHub Stars

2

Maintenance

Last Commit

4yrs ago

Contributors

1

Package

Dependencies

0

License

MIT

Type Definitions

Tree-Shakeable

No?

Categories

Readme

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

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100
No reviews found
Be the first to rate

Alternatives

No alternatives found

Tutorials

No tutorials found
Add a tutorial