GetErrorCode extracts the error code from anywhere in the error chain. Returns empty string if no CodedError is found.
(err error)
| 38 | // GetErrorCode extracts the error code from anywhere in the error chain. |
| 39 | // Returns empty string if no CodedError is found. |
| 40 | func GetErrorCode(err error) string { |
| 41 | if err == nil { |
| 42 | return "" |
| 43 | } |
| 44 | var coded CodedError |
| 45 | if errors.As(err, &coded) { |
| 46 | return coded.Code |
| 47 | } |
| 48 | return "" |
| 49 | } |
| 50 | |
| 51 | // GetErrorSubCode extracts the error subcode from anywhere in the error chain. |
| 52 | // Returns empty string if no CodedError is found or if SubCode is not set. |