Code returns the ErrorCode of err if it, or some error it wraps, is an *Error. If err is context.Canceled or context.DeadlineExceeded, or wraps one of those errors, it returns the Canceled or DeadlineExceeded codes, respectively. If err is nil, it returns the special code OK. Otherwise, it returns U
(err error)
| 111 | // If err is nil, it returns the special code OK. |
| 112 | // Otherwise, it returns Unknown. |
| 113 | func Code(err error) ErrorCode { |
| 114 | if err == nil { |
| 115 | return OK |
| 116 | } |
| 117 | var e *gcerr.Error |
| 118 | if errors.As(err, &e) { |
| 119 | return e.Code |
| 120 | } |
| 121 | if errors.Is(err, context.Canceled) { |
| 122 | return Canceled |
| 123 | } |
| 124 | if errors.Is(err, context.DeadlineExceeded) { |
| 125 | return DeadlineExceeded |
| 126 | } |
| 127 | return Unknown |
| 128 | } |