Stumbled across an interesting issue with an Azure Web App running Node with IIS and wanted to share because I couldn't find information on it.
The problem:
My custom error messages weren't making it down to the client on my production app but were coming through just fine locally.
Quick example:
app.post('/user', function(req, res, next) {
// Parse out the user data
// ...
// Oh no! An error!
if (invalidData) {
return res.status(400).json({error: 'Invalid username, must be at least 4 characters.'});
}
// ...
});
This was coming through my Web App as the standard "400: Bad request..." message rather than my custom error message. On the client I was trying to do JSON.parse(err.responseText).error
which wasn't working as err.responseText
was the "Bad request..."
string rather than my JSON object.