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

How could i serialize and deserialize error to json? #25

Closed
liguangsheng opened this issue Aug 3, 2021 · 1 comment
Closed

How could i serialize and deserialize error to json? #25

liguangsheng opened this issue Aug 3, 2021 · 1 comment

Comments

@liguangsheng
Copy link

No description provided.

@ansel1
Copy link
Owner

ansel1 commented Aug 3, 2021

It's not possible to serialize an error to an exact representation, because error is just an interface, and merry is just a linked list of error interfaces.

You could define a JSON schema for an error that contains the main error attributes merry supports (like HTTP code, user message, stacktrace, source line, etc), or you could try serializing the result of merry.Details(err), but that is a little dangerous, since you don't know the types of the values in that map, and not all types serialize to JSON.

In most RPC APIs I've seen, there is an error structure defined by the API. That error structure is often language-agnostic, so it can be implemented by any language that implements the API. Golang errors (including merry errors) would be converted to and from that API error structure.

@ansel1 ansel1 closed this as completed Aug 3, 2021
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