From d499a6e681c2d15b7c7d021847f8ec5f021158d8 Mon Sep 17 00:00:00 2001 From: constwz Date: Thu, 30 Nov 2023 13:37:50 +0800 Subject: [PATCH] fix:conflict --- base/types/gfsperrors/error.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/base/types/gfsperrors/error.go b/base/types/gfsperrors/error.go index c32ba19e0..d068496a5 100644 --- a/base/types/gfsperrors/error.go +++ b/base/types/gfsperrors/error.go @@ -46,6 +46,26 @@ func init() { }) } +func GetGfSpErr(err error) *GfSpError { + if err == nil { + return nil + } + if gfspErr, ok := err.(*GfSpError); ok { + return gfspErr + } + i := strings.Index(err.Error(), "desc = ") + if i == -1 || len(err.Error())-1 < i+6 { + return nil + } + errInfo := err.Error()[i+6:] + var gfspErr GfSpError + unmarshalErr := json.Unmarshal([]byte(errInfo), &gfspErr) + if unmarshalErr == nil && gfspErr.HttpStatusCode != 0 { + return &gfspErr + } + return nil +} + // MakeGfSpError returns an GfSpError from the build-in error interface. It is // difficult to predefine all errors. For undefined errors, there needs to be a // way to capture them and return them to the client according to the GfSpError