File tree Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change 1+ module . exports = {
2+
3+ beautify : function ( options ) {
4+
5+ var options = options || { } ;
6+
7+ return function ( err , req , res , next ) {
8+ //Catch JSON error
9+ if ( err instanceof SyntaxError &&
10+ err . status >= 400 && err . status < 500 &&
11+ err . message . indexOf ( 'JSON' ) ) {
12+ options . status ? res . status ( options . status ) : res . status ( 400 ) ;
13+ options . res ? res . json ( options . res ) : res . json ( {
14+ msg : 'Invalid JSON'
15+ } ) ;
16+ }
17+ } ;
18+ }
19+ }
Original file line number Diff line number Diff line change 1+ {
2+ "name" : " bodyparser-json-error" ,
3+ "version" : " 0.0.1" ,
4+ "description" : " Beautify Express body-parser JSON syntax error" ,
5+ "main" : " index.js" ,
6+ "scripts" : {
7+ "test" : " echo \" Error: no test specified\" && exit 1"
8+ },
9+ "repository" : {
10+ "type" : " git" ,
11+ "url" : " git+https://github.com/Igor-Lopes/bodyparser-json-error.git"
12+ },
13+ "author" : " Igor Lopes" ,
14+ "license" : " MIT" ,
15+ "bugs" : {
16+ "url" : " https://github.com/Igor-Lopes/bodyparser-json-error/issues"
17+ },
18+ "homepage" : " https://github.com/Igor-Lopes/bodyparser-json-error#readme"
19+ }
You can’t perform that action at this time.
0 commit comments