zotero / zotero-api-node

Zotero API client for Node.js
GNU Affero General Public License v3.0
30 stars 6 forks source link

Error handling #5

Open mrtcode opened 7 years ago

mrtcode commented 7 years ago

This is only the initial version of how the new error handling could look like. This update utilizes https://github.com/zotero/stream-server/pull/8 , which no longer closes the connection on error, but instead returns it as an error event with a message, code and requestID. This update allows to just use a callback function when creating a subscription, and the function is called when a message from stream-server is received with the same requestID. Currently implemented only for subscription creation.

'Reconnect on any error' commit makes zotero-api-node/stream.js to handle connection errors (i.e. ECONNREFUSED) by itself, instead of allowing them to bubble up to arkivo and crash the process. This is not ideal, because arkivo no longer know about errors inside stream.js. But connection error handler should be wrapped by reconnect logic, and currently the reconnect is handled inside stream.js (zotero-api-node). But for now it's still better than allowing process to crash on typical connection errors.

mrtcode commented 7 years ago

So, I think we should use node_redis as an example for error handling. It automatically reconnects and even resubscribes to channels, but it always emits an error event on any connection failure, and if it's not handled then the process will crash. But if handled, Redis will reconnect.