diff --git a/errors.go b/errors.go index dd4dc75..cf054da 100644 --- a/errors.go +++ b/errors.go @@ -59,7 +59,7 @@ type marshalable interface { json.Unmarshaler } -type ErrorCodec interface { +type RPCErrorCodec interface { FromJSONRPCError(JSONRPCError) error ToJSONRPCError() (JSONRPCError, error) } diff --git a/handler.go b/handler.go index 68cdffc..591a6da 100644 --- a/handler.go +++ b/handler.go @@ -284,7 +284,7 @@ func (s *handler) createError(err error) *JSONRPCError { } switch m := err.(type) { - case ErrorCodec: + case RPCErrorCodec: o, err := m.ToJSONRPCError() if err != nil { log.Warnf("Failed to convert error to JSONRPCError: %v", err) @@ -455,12 +455,12 @@ func (s *handler) handle(ctx context.Context, req request, w func(func(io.Writer Message: err.Error(), } - if m, ok := err.(ErrorCodec); ok { - respErr, err := m.ToJSONRPCError() + if m, ok := err.(RPCErrorCodec); ok { + rpcErr, err := m.ToJSONRPCError() if err != nil { log.Warnf("Failed to convert error to JSONRPCError: %v", err) } else { - resp.Error.Data = respErr.Data + respErr.Data = rpcErr.Data } } diff --git a/resp_error_test.go b/resp_error_test.go index 0e56814..e5b2bec 100644 --- a/resp_error_test.go +++ b/resp_error_test.go @@ -35,7 +35,7 @@ func (e *SimpleError) ToJSONRPCError() (JSONRPCError, error) { return JSONRPCError{Message: e.Message}, nil } -var _ ErrorCodec = (*SimpleError)(nil) +var _ RPCErrorCodec = (*SimpleError)(nil) type DataStringError struct { Message string `json:"message"` @@ -62,7 +62,7 @@ func (e *DataStringError) ToJSONRPCError() (JSONRPCError, error) { return JSONRPCError{Message: e.Message, Data: e.Data}, nil } -var _ ErrorCodec = (*DataStringError)(nil) +var _ RPCErrorCodec = (*DataStringError)(nil) type DataComplexError struct { Message string @@ -94,7 +94,7 @@ func (e *DataComplexError) ToJSONRPCError() (JSONRPCError, error) { return JSONRPCError{Message: e.Message, Data: data}, nil } -var _ ErrorCodec = (*DataComplexError)(nil) +var _ RPCErrorCodec = (*DataComplexError)(nil) type MetaError struct { Message string diff --git a/response.go b/response.go index 72f92b4..69885bb 100644 --- a/response.go +++ b/response.go @@ -52,7 +52,7 @@ func (e *JSONRPCError) Error() string { var ( _ error = (*JSONRPCError)(nil) marshalableRT = reflect.TypeOf(new(marshalable)).Elem() - unmarshalableRT = reflect.TypeOf(new(ErrorCodec)).Elem() + unmarshalableRT = reflect.TypeOf(new(RPCErrorCodec)).Elem() ) func (e *JSONRPCError) val(errors *Errors) reflect.Value { @@ -67,7 +67,7 @@ func (e *JSONRPCError) val(errors *Errors) reflect.Value { } if v.Type().Implements(unmarshalableRT) { - _ = v.Interface().(ErrorCodec).FromJSONRPCError(*e) + _ = v.Interface().(RPCErrorCodec).FromJSONRPCError(*e) } if len(e.Meta) > 0 && v.Type().Implements(marshalableRT) {