问题
I've got a tool I'm working on that parses Neo4j responses and emits objects.
https://github.com/brian-gates/neo4j-stream-deserializer
My questions:
- How can I handle errors?
- Is there a better way to handle headers than two parsers? Seems like unnecessary overhead.
The possible error responses look like this:
{ message: 'Error explanation, ... other useful info ... }
Full example:
https://gist.github.com/brian-gates/4a16e0aee13d6e549d52
With successful responses looking like this:
{ columns: [], results: [] }
https://github.com/brian-gates/neo4j-stream-deserializer/blob/master/test/mock/neo4j_response.json
回答1:
You might be interested in Oboe.js, a library which I maintain: Oboe.js on Github
回答2:
Try checking header status. If not 200 OK, don't use the streaming parser, just forward the error to the caller.
It gets more tricky with the transactional cypher endpoint (which responds with 200 if there are errors, because each statement can have separate errors), but with the normal cypher endpoint this should work fine.
来源:https://stackoverflow.com/questions/21566865/parse-streaming-json