Browse Source

Merge branch 'master' into ngram-address-parser

pull/169/head
Harish Krishna 9 years ago
parent
commit
dbd1664042
  1. 7
      middleware/408.js
  2. 5
      middleware/500.js
  3. 2
      package.json

7
middleware/408.js

@ -2,10 +2,11 @@
// handle time out errors
function middleware(err, req, res, next) {
res.header('Cache-Control','no-cache');
if( res.statusCode === 408 || (err.message.toLowerCase().indexOf('request timeout') !== -1) ){
var error = (err && err.message) ? err.message : err;
if( res.statusCode === 408 || (error.toLowerCase().indexOf('request timeout') !== -1) ){
res.status(408);
res.json({ error: err && typeof err.message === 'string' ? err.message : 'request time out' });
res.json({ error: typeof error === 'string' ? error : 'request timeout' });
} else {
next(err);
}

5
middleware/500.js

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

2
package.json

@ -1,7 +1,7 @@
{
"name": "pelias-api",
"author": "mapzen",
"version": "2.1.0",
"version": "2.2.0",
"description": "Pelias API",
"homepage": "https://github.com/pelias/api",
"license": "MIT",

Loading…
Cancel
Save