-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve RPC peer error handling (#7)
Define a new error hierarchy for being unable to complete a method call. Reject method call Promises with instances of the `MethodCallError` subclasses `MethodCallTimeout` or `RPCStreamClosed` in response to the respective events. Define a new error class `UnexpectedResponse`, and emit that instead of a plain `Error` when receiving an unexpected JSON-RPC response object. Reject the method call Promise instead of throwing when calling `callMethod` while the RPC stream is already closed, for consistency with the RPC stream closing while the response is pending. No longer assert that the Writable side of the Peer is open in the `sendNotification` and `pushError` methods. This is consistent with the behaviour of the `Readable.push` method, and allows Peer to be operated in a simplex mode for sending notifications. This change also fixes a bug with handling of a request handler's error response when the Writable side is closed. Before, success responses were pushed to the Readable side but errors resulted in an unhandled Promise rejection within the library and no response being pushed. Now all responses are pushed to the Readable side irrespective of the response type or state of the Peer's Writable side.
- Loading branch information
Showing
3 changed files
with
176 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters