Skip to content

Commit e8dc77a

Browse files
author
Aryan Tikarya
committed
rename the interface
1 parent ef506b1 commit e8dc77a

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

errors.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ type marshalable interface {
5959
json.Unmarshaler
6060
}
6161

62-
type ErrorCodec interface {
62+
type RPCErrorCodec interface {
6363
FromJSONRPCError(JSONRPCError) error
6464
ToJSONRPCError() (JSONRPCError, error)
6565
}

handler.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ func (s *handler) createError(err error) *JSONRPCError {
284284
}
285285

286286
switch m := err.(type) {
287-
case ErrorCodec:
287+
case RPCErrorCodec:
288288
o, err := m.ToJSONRPCError()
289289
if err != nil {
290290
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
455455
Message: err.Error(),
456456
}
457457

458-
if m, ok := err.(ErrorCodec); ok {
459-
respErr, err := m.ToJSONRPCError()
458+
if m, ok := err.(RPCErrorCodec); ok {
459+
rpcErr, err := m.ToJSONRPCError()
460460
if err != nil {
461461
log.Warnf("Failed to convert error to JSONRPCError: %v", err)
462462
} else {
463-
resp.Error.Data = respErr.Data
463+
respErr.Data = rpcErr.Data
464464
}
465465
}
466466

resp_error_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func (e *SimpleError) ToJSONRPCError() (JSONRPCError, error) {
3535
return JSONRPCError{Message: e.Message}, nil
3636
}
3737

38-
var _ ErrorCodec = (*SimpleError)(nil)
38+
var _ RPCErrorCodec = (*SimpleError)(nil)
3939

4040
type DataStringError struct {
4141
Message string `json:"message"`
@@ -62,7 +62,7 @@ func (e *DataStringError) ToJSONRPCError() (JSONRPCError, error) {
6262
return JSONRPCError{Message: e.Message, Data: e.Data}, nil
6363
}
6464

65-
var _ ErrorCodec = (*DataStringError)(nil)
65+
var _ RPCErrorCodec = (*DataStringError)(nil)
6666

6767
type DataComplexError struct {
6868
Message string
@@ -94,7 +94,7 @@ func (e *DataComplexError) ToJSONRPCError() (JSONRPCError, error) {
9494
return JSONRPCError{Message: e.Message, Data: data}, nil
9595
}
9696

97-
var _ ErrorCodec = (*DataComplexError)(nil)
97+
var _ RPCErrorCodec = (*DataComplexError)(nil)
9898

9999
type MetaError struct {
100100
Message string

response.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func (e *JSONRPCError) Error() string {
5252
var (
5353
_ error = (*JSONRPCError)(nil)
5454
marshalableRT = reflect.TypeOf(new(marshalable)).Elem()
55-
unmarshalableRT = reflect.TypeOf(new(ErrorCodec)).Elem()
55+
unmarshalableRT = reflect.TypeOf(new(RPCErrorCodec)).Elem()
5656
)
5757

5858
func (e *JSONRPCError) val(errors *Errors) reflect.Value {
@@ -67,7 +67,7 @@ func (e *JSONRPCError) val(errors *Errors) reflect.Value {
6767
}
6868

6969
if v.Type().Implements(unmarshalableRT) {
70-
_ = v.Interface().(ErrorCodec).FromJSONRPCError(*e)
70+
_ = v.Interface().(RPCErrorCodec).FromJSONRPCError(*e)
7171
}
7272

7373
if len(e.Meta) > 0 && v.Type().Implements(marshalableRT) {

0 commit comments

Comments
 (0)