Merge pull request #10 from strongloop/handling-res-statuscode
Handle error from res.statusCode
This commit is contained in:
commit
a5129595ef
|
@ -42,6 +42,10 @@ exports = module.exports = function createStrongErrorHandler(options) {
|
||||||
return req.socket.destroy();
|
return req.socket.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// this will alter the err object, to handle when res.statusCode is an error
|
||||||
|
if (!err.status && !err.statusCode && res.statusCode >= 400)
|
||||||
|
err.statusCode = res.statusCode;
|
||||||
|
|
||||||
var data = buildResponseData(err, isDebugMode);
|
var data = buildResponseData(err, isDebugMode);
|
||||||
debug('Response status %s data %j', data.statusCode, data);
|
debug('Response status %s data %j', data.statusCode, data);
|
||||||
|
|
||||||
|
|
|
@ -65,6 +65,19 @@ describe('strong-error-handler', function() {
|
||||||
|
|
||||||
request.get('/').expect(400, done);
|
request.get('/').expect(400, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('handles error from `res.statusCode`', function(done) {
|
||||||
|
givenErrorHandlerForError();
|
||||||
|
var handler = _requestHandler;
|
||||||
|
_requestHandler = function(req, res, next) {
|
||||||
|
res.statusCode = 507;
|
||||||
|
handler(req, res, next);
|
||||||
|
};
|
||||||
|
request.get('/').expect(
|
||||||
|
507,
|
||||||
|
{error: {statusCode: 507, message: 'Insufficient Storage'}},
|
||||||
|
done);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
context('logging', function() {
|
context('logging', function() {
|
||||||
|
|
Loading…
Reference in New Issue