What is the proper way to unmarshal an error when ...
# talk-kratos
p
What is the proper way to unmarshal an error when using the kratos client-go API? I get a response and the body contains an error, but I see no public methods or structs to unmarhsal the error. This is self-hosted.
I found it. For those looking:
Copy code
b, _ := ioutil.ReadAll(resp.Body)
e := &client.NullableJsonError{}
_ := e.UnmarshalJSON(b)
genericError := e.Get().Error
s
or
Copy code
var e client.NullableJsonError
err := json.NewDecoder(resp.Body).Unmarshal(&e)
p
Oh, very nice. Thanks. I'm very much not used to the chaining style of Go Ory uses.
s
I'd say this this is more of a standard go thing 😉
p
I'd disagree! Alas.
s
btw the sdks are generated from the openapi spec, we'd love to give you a nicer experience, but that is so much work...
p
Yeah, it's a bit of a slog trying to sort out what's what, That's fine though.
Is there any documentation about return values?
resp
vs
error
when something goes wrong? And how to unpack Reason vs. Details vs. Message in the Error.
And how to read
Traits
from an
Identity
? I assume there's a nice way to do this without having to cast.