Skip to content

Commit 9ef484a

Browse files
author
Aryan Tikarya
committed
address comments
1 parent 90c8605 commit 9ef484a

File tree

2 files changed

+6
-19
lines changed

2 files changed

+6
-19
lines changed

handler.go

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ func (s *handler) createError(err error) *JSONRPCError {
287287
case RPCErrorCodec:
288288
o, err := m.ToJSONRPCError()
289289
if err != nil {
290-
log.Warnf("Failed to convert error to JSONRPCError: %v", err)
290+
log.Errorf("Failed to convert error to JSONRPCError: %w", err)
291291
} else {
292292
out = &o
293293
}
@@ -296,7 +296,7 @@ func (s *handler) createError(err error) *JSONRPCError {
296296
if marshalErr == nil {
297297
out.Meta = meta
298298
} else {
299-
log.Warnf("Failed to marshal error metadata: %v", marshalErr)
299+
log.Errorf("Failed to marshal error metadata: %w", marshalErr)
300300
}
301301
}
302302

@@ -450,21 +450,10 @@ func (s *handler) handle(ctx context.Context, req request, w func(func(io.Writer
450450
log.Warnf("failed to setup channel in RPC call to '%s': %+v", req.Method, err)
451451
stats.Record(ctx, metrics.RPCResponseError.M(1))
452452

453-
respErr := &JSONRPCError{
453+
resp.Error = &JSONRPCError{
454454
Code: 1,
455455
Message: err.Error(),
456456
}
457-
458-
if m, ok := err.(RPCErrorCodec); ok {
459-
rpcErr, err := m.ToJSONRPCError()
460-
if err != nil {
461-
log.Warnf("Failed to convert error to JSONRPCError: %v", err)
462-
} else {
463-
respErr.Data = rpcErr.Data
464-
}
465-
}
466-
467-
resp.Error = respErr
468457
} else {
469458
resp.Result = res
470459
}

response.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,12 @@ func (e *JSONRPCError) val(errors *Errors) reflect.Value {
6868

6969
if v.Type().Implements(errorCodecRT) {
7070
if err := v.Interface().(RPCErrorCodec).FromJSONRPCError(*e); err != nil {
71-
log.Errorf("Error converting JSONRPCError (code %d) to custom error type '%s': %w", e.Code, t.String(), err)
71+
log.Errorf("Error converting JSONRPCError to custom error type '%s' (code %d): %w", t.String(), e.Code, err)
7272
return reflect.ValueOf(e)
7373
}
74-
}
75-
76-
if len(e.Meta) > 0 && v.Type().Implements(marshalableRT) {
74+
} else if len(e.Meta) > 0 && v.Type().Implements(marshalableRT) {
7775
if err := v.Interface().(marshalable).UnmarshalJSON(e.Meta); err != nil {
78-
log.Errorf("Error unmarshaling metadata for error type '%s': %w", t.String(), err)
76+
log.Errorf("Error unmarshalling error metadata to custom error type '%s' (code %d): %w", t.String(), e.Code, err)
7977
return reflect.ValueOf(e)
8078
}
8179
}

0 commit comments

Comments
 (0)