You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
When I send JSON2-RPC (and others), I would like to check if there were any errors, but I do not need to parse the content of the message, for example, because I know it will always be empty. Currently, the DecodeClientResponse() will fail if I provide parameter reply == nil, as the Unmarshall() is not able to handle it. It would make sense in my eyes to allow for such an option.
Describe the solution you'd like
The API change would be negligible - only from now on, on providing reply == nil, an error would be returned only if the RPC itself would return an error. it would be enough just to add:
if reply == nil {
return nil
}
to the DecodeClientResponse() code:
// DecodeClientResponse decodes the response body of a client request into
// the interface reply.
func DecodeClientResponse(r io.Reader, reply interface{}) error {
var c clientResponse
if err := json.NewDecoder(r).Decode(&c); err != nil {
return err
}
if c.Error != nil {
jsonErr := &Error{}
if err := json.Unmarshal(*c.Error, jsonErr); err != nil {
return &Error{
Code: E_SERVER,
Message: string(*c.Error),
}
}
return jsonErr
}
if c.Result == nil {
return ErrNullResult
}
if reply == nil {
return nil
}
return json.Unmarshal(*c.Result, reply)
}
Describe alternatives you've considered
The workaround is to set the reply to a struct with string inside and ignore the results. This seems unnecessarily complicated.
…
The text was updated successfully, but these errors were encountered:
Is your feature request related to a problem? Please describe.
Describe the solution you'd like
to the DecodeClientResponse() code:
Describe alternatives you've considered
…
The text was updated successfully, but these errors were encountered: