Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should always throw Error instead of JSON-RPC ErrorObject #18

Open
kael-shipman opened this issue Dec 4, 2019 · 1 comment
Open

Should always throw Error instead of JSON-RPC ErrorObject #18

kael-shipman opened this issue Dec 4, 2019 · 1 comment

Comments

@kael-shipman
Copy link

I know this is a bit of a code philosophy issue more than a strict right/wrong, so I submit it more as a suggestion with opinions about how it might be implemented.

Problem: I spent an hour last night trying to figure out where an error was coming from because my global error-handler was expecting a standard Error object and the code was throwing a simple JSON-RPC ErrorObject (i.e., no "message" and no stack trace).

Suggestion: Why don't we create an extension of Error that has a serialize method on it which returns the JSON-RPC representation of the error and throw that instead? That way standard error handling machinery would continue to work as expected using the standard message and stack trace of the Error object, while JSON-RPC machinery could easily translate that into an appropriate response.

I'd be happy to work on this if you're interested, or to hash over other solutions. Lemme know.

@kraenhansen
Copy link

kraenhansen commented Nov 16, 2023

I agree with @kael-shipman on this. I'd expect a parsed JsonRpcError to extend Error.

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

No branches or pull requests

2 participants