Browse Source

middleware fix

pull/159/head
Harish Krishna 10 years ago
parent
commit
793182148a
  1. 8
      middleware/408.js
  2. 2
      middleware/500.js

8
middleware/408.js

@ -2,8 +2,12 @@
// handle time out errors // handle time out errors
function middleware(err, req, res, next) { function middleware(err, req, res, next) {
res.header('Cache-Control','no-cache'); res.header('Cache-Control','no-cache');
if( res.statusCode === 408 ){ res.status(408); } if( res.statusCode === 408 ){
res.json({ error: typeof err === 'string' ? err : 'request time out' }); res.status(408);
res.json({ error: err && typeof err.message === 'string' ? err.message : 'request time out' });
} else {
next(err);
}
} }
module.exports = middleware; module.exports = middleware;

2
middleware/500.js

@ -5,7 +5,7 @@ function middleware(err, req, res, next) {
logger.error( 'Error: `%s`. Stack trace: `%s`.', err, err.stack ); logger.error( 'Error: `%s`. Stack trace: `%s`.', err, err.stack );
res.header('Cache-Control','no-cache'); res.header('Cache-Control','no-cache');
if( res.statusCode < 400 ){ res.status(500); } if( res.statusCode < 400 ){ res.status(500); }
res.json({ error: typeof err === 'string' ? err : 'internal server error' }); res.json({ error: err && typeof err.message === 'string' ? err.message : 'internal server error' });
} }
module.exports = middleware; module.exports = middleware;

Loading…
Cancel
Save