File tree Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -59,6 +59,13 @@ type marshalable interface {
5959 json.Unmarshaler
6060}
6161
62+ // Error wraps RPC errors, which contain an error code in addition to the message.
63+ type Error interface {
64+ Error () string // returns the message
65+ ErrorCode () int // returns the code
66+ }
67+
68+ // DataError contains extra data to explain the error
6269type DataError interface {
6370 Error () string // returns the message
6471 ErrorData () interface {} // returns the error data
Original file line number Diff line number Diff line change @@ -365,7 +365,13 @@ func (s *handler) createError(err error) *respError {
365365 }
366366 }
367367
368- if de , ok := err .(DataError ); ok {
368+ var err2 Error
369+ if errors .As (err , & err2 ) {
370+ out .Code = ErrorCode (err2 .ErrorCode ())
371+ }
372+
373+ var de DataError
374+ if errors .As (err , & de ) {
369375 out .Data = de .ErrorData ()
370376 }
371377
You can’t perform that action at this time.
0 commit comments