Skip to content

Igor-Lopes/bodyparser-json-error

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Beautify Express body-parser syntax error

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published