MCPcopy Index your code
hub / github.com/go-dev-frame/sponge / ParseError

Function ParseError

pkg/errcode/http_error.go:172–200  ·  view source on GitHub ↗

ParseError parsing out error codes from error messages

(err error)

Source from the content-addressed store, hash-verified

170
171// ParseError parsing out error codes from error messages
172func ParseError(err error) *Error {
173 if err == nil {
174 return Success
175 }
176
177 outError := &Error{
178 code: -1,
179 msg: "unknown error",
180 }
181
182 splits := strings.Split(err.Error(), ", msg = ")
183 codeStr := strings.ReplaceAll(splits[0], "code = ", "")
184 code, er := strconv.Atoi(codeStr)
185 if er != nil {
186 return outError
187 }
188
189 if e, ok := errCodes[code]; ok {
190 if len(splits) > 1 {
191 outError.code = code
192 outError.msg = splits[1]
193 outError.needHTTPCode = strings.Contains(err.Error(), ToHTTPCodeLabel)
194 return outError
195 }
196 return e
197 }
198
199 return outError
200}
201
202// GetErrorCode get Error code from error returned by http invoke
203func GetErrorCode(err error) int {

Callers 3

GetErrorCodeFunction · 0.85
TestParseErrorFunction · 0.85
handleHTTPErrorMethod · 0.85

Calls 1

ErrorMethod · 0.65

Tested by 1

TestParseErrorFunction · 0.68