Skip to content

Commit

Permalink
rename the interface
Browse files Browse the repository at this point in the history
  • Loading branch information
akaladarshi committed Oct 22, 2024
1 parent ef506b1 commit e8dc77a
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ type marshalable interface {
json.Unmarshaler
}

type ErrorCodec interface {
type RPCErrorCodec interface {
FromJSONRPCError(JSONRPCError) error
ToJSONRPCError() (JSONRPCError, error)
}
8 changes: 4 additions & 4 deletions handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
}

Expand Down
6 changes: 3 additions & 3 deletions resp_error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions response.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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) {
Expand Down

0 comments on commit e8dc77a

Please sign in to comment.