From 3d520949b454f3eb4139b07dd60d0f6bbaf5ea33 Mon Sep 17 00:00:00 2001 From: franklin Date: Mon, 10 Jul 2023 09:03:31 +0200 Subject: [PATCH] fix: add nil check --- gotsrpc.go | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/gotsrpc.go b/gotsrpc.go index f3649c8..d997601 100644 --- a/gotsrpc.go +++ b/gotsrpc.go @@ -110,18 +110,16 @@ 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 errResp != nil { - if v, ok := errResp.(interface { - Error() string - }); ok { - stats.ErrorCode = 1 - stats.ErrorMessage = v.Error() - } - if v, ok := errResp.(interface { - ErrorCode() int - }); ok { - stats.ErrorCode = v.ErrorCode() - } + if v, ok := errResp.(interface { + Error() string + }); ok && v != nil { + stats.ErrorCode = 1 + stats.ErrorMessage = v.Error() + } + if v, ok := errResp.(interface { + ErrorCode() int + }); ok && v != nil { + stats.ErrorCode = v.ErrorCode() } } }