GetErrorSubCode extracts the error subcode from anywhere in the error chain. Returns empty string if no CodedError is found or if SubCode is not set.
(err error)
| 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. |
| 53 | func GetErrorSubCode(err error) string { |
| 54 | if err == nil { |
| 55 | return "" |
| 56 | } |
| 57 | var coded CodedError |
| 58 | if errors.As(err, &coded) { |
| 59 | return coded.SubCode |
| 60 | } |
| 61 | return "" |
| 62 | } |
| 63 | |
| 64 | // Errorf creates a formatted error wrapped in a CodedError. |
| 65 | // This is a convenience function that combines fmt.Errorf with MakeCodedError. |