go-res
go-res copied to clipboard
Add the `(*Error).DecodeData` method
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?