Skip to content
This repository has been archived by the owner on May 17, 2019. It is now read-only.

Investigate ways to improve rpc error handling #19

Closed
ganemone opened this issue Nov 28, 2017 · 2 comments
Closed

Investigate ways to improve rpc error handling #19

ganemone opened this issue Nov 28, 2017 · 2 comments

Comments

@ganemone
Copy link
Contributor

ganemone commented Nov 28, 2017

The current process for failing an RPC is to return a Promise that rejects. This works fairly well, however it falls a bit short when you want to serialize data with the RPC failure.

It is generally good practice to only instances of an Error object to Promise.reject(), and similarly to only throw Error objects (see https://eslint.org/docs/rules/prefer-promise-reject-errors and https://eslint.org/docs/rules/no-throw-literal). However, lets say you want to signal an RPC failure, and you want to serialize some JSON down to the client. We currently only send the error.message data to the client, meaning you are very restricted in how you handle errors.

Node has somewhat recently standardized on using Error.code to signal the type of error (see https://nodejs.org/api/errors.html#errors_error_code). A good first step would be supporting this property on the rejected error.

If error.code is not enough (which I suspect it won't be), we could support serializing arbitrary JSON on the error.meta key.

Thoughts?

@AlexMSmithCA
Copy link
Member

This sounds reasonable to me. To make sure I understand, is the proposal for error.meta to contain an arbitrary payload that contains additional context for the error? Or is it for supporting non-standard error codes?

In either case, I agree error.message isn't great for robustly handling errors.

@ganemone
Copy link
Contributor Author

ganemone commented Nov 28, 2017

Basically we will serialize error.message, error.code and error.meta from the server to the browser so that you can use it in your application

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants