StatusErrorMatch checks if err was caused by StatusError. Can optionally also check whether the StatusError's status code matches one of the supplied status codes in matchStatus. Returns the matched StatusError status code and true if match criteria are met, otherwise false.
(err error, matchStatusCodes ...int)
| 46 | // status code matches one of the supplied status codes in matchStatus. |
| 47 | // Returns the matched StatusError status code and true if match criteria are met, otherwise false. |
| 48 | func StatusErrorMatch(err error, matchStatusCodes ...int) (int, bool) { |
| 49 | var statusErr StatusError |
| 50 | |
| 51 | if errors.As(err, &statusErr) { |
| 52 | statusCode := statusErr.Status() |
| 53 | |
| 54 | if len(matchStatusCodes) <= 0 { |
| 55 | return statusCode, true |
| 56 | } |
| 57 | |
| 58 | if slices.Contains(matchStatusCodes, statusCode) { |
| 59 | return statusCode, true |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | return -1, false |
| 64 | } |
| 65 | |
| 66 | // StatusErrorCheck returns whether or not err was caused by a StatusError and if it matches one of the |
| 67 | // optional status codes. |
no test coverage detected
searching dependent graphs…