add logging for error handling edge cases #742

Closed
wants to merge 4 commits into
from

Conversation

Projects
None yet
4 participants
@missinglink
Member

missinglink commented Dec 2, 2016

add logging for error handling edge cases

@@ -42,7 +43,10 @@ function sendJSONResponse(req, res, next) {
if( err instanceof es.errors.RequestTimeout ){ statusCode = Math.max( statusCode, 408 ); }
else if( err instanceof es.errors.NoConnections ){ statusCode = Math.max( statusCode, 502 ); }
else if( err instanceof es.errors.ConnectionFault ){ statusCode = Math.max( statusCode, 502 ); }
- else { statusCode = Math.max( statusCode, 500 ); }
+ else {
+ logger.warn( 'unknown geocoding error object:', err.constructor.name, err );

This comment has been minimized.

@dianashk

dianashk Dec 2, 2016

Contributor

i thought we were going to check for existance of err.contructor here? seems a bit optimistic to assume it's there

@dianashk

dianashk Dec 2, 2016

Contributor

i thought we were going to check for existance of err.contructor here? seems a bit optimistic to assume it's there

This comment has been minimized.

@missinglink

missinglink Dec 2, 2016

Member

I had a think about it and the if( err instanceof Error ){ check above guarantees that err.constructor.name will always exist.

@missinglink

missinglink Dec 2, 2016

Member

I had a think about it and the if( err instanceof Error ){ check above guarantees that err.constructor.name will always exist.

This comment has been minimized.

@missinglink

missinglink Dec 2, 2016

Member
var err = new Error()

err.constructor.name;
"Error"

delete err.constructor
true

err.constructor.name;
"Error"
@missinglink

missinglink Dec 2, 2016

Member
var err = new Error()

err.constructor.name;
"Error"

delete err.constructor
true

err.constructor.name;
"Error"

This comment has been minimized.

@missinglink

missinglink Dec 2, 2016

Member
function MyError(){}
MyError.constructor = Error.Constructor;

var err = new MyError()

err.constructor.name;
"MyError"
@missinglink

missinglink Dec 2, 2016

Member
function MyError(){}
MyError.constructor = Error.Constructor;

var err = new MyError()

err.constructor.name;
"MyError"

This comment has been minimized.

@missinglink

missinglink Dec 2, 2016

Member

for some reason.. even with a typo the above works :P

@missinglink

missinglink Dec 2, 2016

Member

for some reason.. even with a typo the above works :P

This comment has been minimized.

@missinglink

missinglink Dec 2, 2016

Member

oh right, it works for any function:

function test(){}

test.constructor.name;
"Function"
@missinglink

missinglink Dec 2, 2016

Member

oh right, it works for any function:

function test(){}

test.constructor.name;
"Function"

This comment has been minimized.

@missinglink

missinglink Dec 2, 2016

Member

and because javascript; everything apparently

(99).constructor.name
"Number"
@missinglink

missinglink Dec 2, 2016

Member

and because javascript; everything apparently

(99).constructor.name
"Number"

This comment has been minimized.

@missinglink

missinglink Dec 2, 2016

Member

oh javascript...

(NaN).constructor.name
"Number"
@missinglink

missinglink Dec 2, 2016

Member

oh javascript...

(NaN).constructor.name
"Number"
- if( res.statusCode < 400 ){ res.status(500); }
- res.json({ error: typeof error === 'string' ? error : 'internal server error' });
+ if( res.statusCode < 400 ){
+ logger.info( 'status code changed from', res.statusCode, 'to 500' );

This comment has been minimized.

@trescube

trescube Dec 2, 2016

Contributor

I think you need spaces after from and before to.

@trescube

trescube Dec 2, 2016

Contributor

I think you need spaces after from and before to.

This comment has been minimized.

@missinglink

missinglink Dec 2, 2016

Member
console.log( "doesn't", "it", "add", "them", "for", "me?" );
doesn't it add them for me?
@missinglink

missinglink Dec 2, 2016

Member
console.log( "doesn't", "it", "add", "them", "for", "me?" );
doesn't it add them for me?

This comment has been minimized.

@trescube

trescube Dec 2, 2016

Contributor

Ah, I learn something new about javascript every day!

@trescube

trescube Dec 2, 2016

Contributor

Ah, I learn something new about javascript every day!

@orangejulius orangejulius referenced this pull request Dec 5, 2016

Merged

Improved logging #751

@orangejulius

This comment has been minimized.

Show comment
Hide comment
@orangejulius

orangejulius Dec 5, 2016

Member

Superseded by #751

Member

orangejulius commented Dec 5, 2016

Superseded by #751

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment