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

Add the (*Error).DecodeData method #105

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

remyduthu
Copy link
Contributor

@remyduthu remyduthu commented Sep 17, 2024

The goal of this method is to help decoding the data field of an error.

The problem is that the type conversion is not working in most cases. For example, the following code is not working:

type User{}
user, ok := err.Data.(*User)
// ...

We have to do:

rawData, _ := json.Marshal(err.Data)

type User{}
user := &User{}

_ = json.Unmarshal(rawData, user)

Now, with this method, we can do:

type User{}
user := &User{}
_ = err.DecodeData(user)

What do you think about that @jirenius?

@remyduthu remyduthu changed the title Add the (*Error).DecodeData method Add the (*Error).DecodeData method Sep 17, 2024
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

Successfully merging this pull request may close these issues.

1 participant