node.js - Custom Error Messages in Node Azure Web App -


stumbled across interesting issue azure web app running node iis , wanted share because couldn't find information on it.

the problem:

my custom error messages weren't making down client on production app coming through fine locally.

quick example:

app.post('/user', function(req, res, next) {     // parse out user data     // ...     // oh no! error!     if (invaliddata) {         return res.status(400).json({error: 'invalid username, must @ least 4 characters.'});     }     // ... }); 

this coming through web app standard "400: bad request..." message rather custom error message. on client trying json.parse(err.responsetext).error wasn't working err.responsetext "bad request..." string rather json object.

the solution!

in web.config file add line between <system.webserver> ... </system.webserver>:

<httperrors existingresponse="passthrough" />

hopefully nobody else hits issue did. i'm sure mix of incorrect googling , inexperience iis never found answer online, stumbled across few links led me iis error handling page.

hope helps else! there's ton of info in doc if you're running iis web app, highly recommend reading through it.


Comments