From 381cb1917a764204224f3bddf83751013f1b488f Mon Sep 17 00:00:00 2001 From: Harish Krishna Date: Wed, 15 Jul 2015 15:18:51 -0400 Subject: [PATCH 1/5] big fix - err is of type string if there is an error within express app - its of type object (with .message being string) in case of errors messages from the ES cluster --- middleware/408.js | 6 ++++-- middleware/500.js | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/middleware/408.js b/middleware/408.js index 2b2a7b8a..9688af2e 100644 --- a/middleware/408.js +++ b/middleware/408.js @@ -2,9 +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.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: error === 'string' ? error : 'request time out' }); } else { next(err); } diff --git a/middleware/500.js b/middleware/500.js index 9f274e23..373ef958 100644 --- a/middleware/500.js +++ b/middleware/500.js @@ -4,8 +4,9 @@ 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; 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; From b3f85ebc17d94e564eefc1132c6c6b4bfa486487 Mon Sep 17 00:00:00 2001 From: Harish Krishna Date: Mon, 20 Jul 2015 16:41:03 -0400 Subject: [PATCH 2/5] err & err.message instead of err.message --- middleware/408.js | 2 +- middleware/500.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/middleware/408.js b/middleware/408.js index 9688af2e..92dc9723 100644 --- a/middleware/408.js +++ b/middleware/408.js @@ -2,7 +2,7 @@ // handle time out errors function middleware(err, req, res, next) { res.header('Cache-Control','no-cache'); - var error = err.message ? err.message : err; + var error = (err && err.message) ? err.message : err; if( res.statusCode === 408 || (error.toLowerCase().indexOf('request timeout') !== -1) ){ res.status(408); diff --git a/middleware/500.js b/middleware/500.js index 373ef958..cc3f8325 100644 --- a/middleware/500.js +++ b/middleware/500.js @@ -4,7 +4,8 @@ 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: typeof error === 'string' ? error : 'internal server error' }); } From 8e17f2817078fe264cb645290899f772e6b88c41 Mon Sep 17 00:00:00 2001 From: Harish Krishna Date: Mon, 20 Jul 2015 16:46:26 -0400 Subject: [PATCH 3/5] typeof error should be string --- middleware/408.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/middleware/408.js b/middleware/408.js index 92dc9723..109fa5eb 100644 --- a/middleware/408.js +++ b/middleware/408.js @@ -6,7 +6,7 @@ function middleware(err, req, res, next) { if( res.statusCode === 408 || (error.toLowerCase().indexOf('request timeout') !== -1) ){ res.status(408); - res.json({ error: error === 'string' ? error : 'request time out' }); + res.json({ error: typeof error === 'string' ? error : 'request time out' }); } else { next(err); } From 3ed4842e86bb2713d4f8500e5a53fbdd7329fdf3 Mon Sep 17 00:00:00 2001 From: Harish Krishna Date: Tue, 21 Jul 2015 09:44:12 -0400 Subject: [PATCH 4/5] timeout is one word --- middleware/408.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/middleware/408.js b/middleware/408.js index 109fa5eb..ffbb6066 100644 --- a/middleware/408.js +++ b/middleware/408.js @@ -6,7 +6,7 @@ function middleware(err, req, res, next) { if( res.statusCode === 408 || (error.toLowerCase().indexOf('request timeout') !== -1) ){ res.status(408); - res.json({ error: typeof error === 'string' ? error : 'request time out' }); + res.json({ error: typeof error === 'string' ? error : 'request timeout' }); } else { next(err); } From 5401ed996213415338197a4342100fa5ac034376 Mon Sep 17 00:00:00 2001 From: Harish Krishna Date: Tue, 21 Jul 2015 10:01:05 -0400 Subject: [PATCH 5/5] 2.2.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b59a6ffc..5cdf3c32 100644 --- a/package.json +++ b/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",