File tree Expand file tree Collapse file tree 1 file changed +50
-0
lines changed Expand file tree Collapse file tree 1 file changed +50
-0
lines changed Original file line number Diff line number Diff line change 11# bodyparser-json-error  
22Beautify body parser JSON syntax error
3+ 
4+ ## Installation  
5+ 
6+ ``` 
7+ npm install bodyparser-json-error --save 
8+ ``` 
9+ 
10+ ## Usage  
11+ 
12+ ``` javascript 
13+ 
14+ var  express =  require (' express'  );
15+ var  bodyParser =  require (' body-parser'  );
16+ var  bodyParserError =  require (' bodyparser-json-error'  );
17+ 
18+ var  app =  express ();
19+ 
20+ app .use (bodyParser .urlencoded ({
21+     extended:  true 
22+ }));
23+ app .use (bodyParser .json ());
24+ 
25+ //  Beautify body parser json syntax error
26+ app .use (bodyParserError .beautify ());
27+ 
28+ ``` 
29+ 
30+ ## Middleware Options  
31+ You can optionally set the status code and response for the body parser syntax error.
32+ 
33+ ``` javascript 
34+ app .use (bodyParserError .beautify ({status:  500  , res:  {msg:  ' You sent a bad JSON !'  }}));
35+ ``` 
36+ 
37+ The output:
38+ 
39+ ** HTTP Status Code:**  400 
40+ 
41+ ``` javascript 
42+ {
43+   " msg" :  " You sent a bad JSON !" 
44+ }
45+ ``` 
46+ 
47+ ### Options  
48+ *  status: The response status code. ** Default:**  400
49+ *  res: The response body. ** Default:**  `` {msg: 'Invalid JSON'} `` 
50+ 
51+ ## License  
52+ MIT License
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments