HasCode checks and reports whether `err` has `code` in its chaining errors.
(err error, code gcode.Code)
| 129 | |
| 130 | // HasCode checks and reports whether `err` has `code` in its chaining errors. |
| 131 | func HasCode(err error, code gcode.Code) bool { |
| 132 | if err == nil { |
| 133 | return false |
| 134 | } |
| 135 | if e, ok := err.(ICode); ok && code == e.Code() { |
| 136 | return true |
| 137 | } |
| 138 | if e, ok := err.(IUnwrap); ok { |
| 139 | return HasCode(e.Unwrap(), code) |
| 140 | } |
| 141 | return false |
| 142 | } |
searching dependent graphs…