You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on May 17, 2019. It is now read-only.
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?
The text was updated successfully, but these errors were encountered:
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.
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 toPromise.reject()
, and similarly to only throwError
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 theerror.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?
The text was updated successfully, but these errors were encountered: