Brian Gates
Brian Gates

Reputation: 514

Parse streaming JSON

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:

  1. How can I handle errors?
  2. 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

Upvotes: 1

Views: 1266

Answers (2)

Eve Freeman
Eve Freeman

Reputation: 33175

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.

Upvotes: 1

jimhigson
jimhigson

Reputation: 192

You might be interested in Oboe.js, a library which I maintain: Oboe.js on Github

Upvotes: 1

Related Questions