Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include neo4j's original error in error objects #120

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/util.coffee
Expand Up @@ -93,6 +93,9 @@ exports.adjustError = (error) ->

error = new Error
error.message = serverError.message or serverError
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've also been wondering if all of node-neo4j's errors that come from Neo4j errors should get their message prefixed with e.g. "Neo4j FooBarException:" (just like the no-message case just above this).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Not something you need to "fix" in this PR of course. Just an observation; curious if you have thoughts.)


# Attach original error to expose neo4j's error stack and code
error.originalError = serverError

if typeof error isnt 'object'
error = new Error error
Expand All @@ -102,7 +105,7 @@ exports.adjustError = (error) ->
# see: http://stackoverflow.com/a/9254101/132978
if error.code is 'ECONNREFUSED'
error.message = "Couldn't reach database (connection refused)."

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: get rid of this extraneous trailing whitespace.

return error

#-----------------------------------------------------------------------------
Expand Down
12 changes: 12 additions & 0 deletions test/cypher._coffee
Expand Up @@ -166,3 +166,15 @@ user9 = users[9]
expect(results[0]['path'].relationships).to.have.length 2
expect(results[0]['path'].relationships[1]).to.be.an 'object'
# expect(results[0]['path'].relationships[1].type).to.eq 'follows'

'neo4j error': (_) ->
try
results = db.query """
START notfound=node(999999)
""", _
catch err
expect(err.originalError).to.be.an 'object'
expect(err.originalError.message).to.be.an 'string'
expect(err.originalError.exception).to.be.an 'string'
expect(err.originalError.stacktrace).to.be.an 'array'
expect(err.originalError.message).to.eql err.message