Skip to content

Commit

Permalink
fix: use reflect
Browse files Browse the repository at this point in the history
  • Loading branch information
franklinkim committed Jul 10, 2023
1 parent 529eb4c commit 57cd3ac
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions gotsrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"os"
"path"
"path/filepath"
"reflect"
"sort"
"strings"
"time"
Expand Down Expand Up @@ -110,13 +111,15 @@ func Reply(response []interface{}, stats *CallStats, r *http.Request, w http.Res
stats.Marshalling = time.Since(serializationStart)
if len(response) > 0 {
errResp := response[len(response)-1]
if v, ok := errResp.(error); ok && v != nil {
stats.ErrorCode = 1
stats.ErrorMessage = v.Error()
if v, ok := v.(interface {
ErrorCode() int
}); ok && v != nil {
stats.ErrorCode = v.ErrorCode()
if !reflect.ValueOf(errResp).IsNil() {
if v, ok := errResp.(error); ok {
stats.ErrorCode = 1
stats.ErrorMessage = v.Error()
if v, ok := v.(interface {
ErrorCode() int
}); ok {
stats.ErrorCode = v.ErrorCode()
}
}
}
}
Expand Down

0 comments on commit 57cd3ac

Please sign in to comment.