Performs a deep check of wrapped errors to find one which is selected by the given classifier func. The classifer is called on all non-nil errors found, starting with topErr, then on each inner wrapped error in turn until it returns non-nil which ends the scan. If the classifier ever returns a non-
( topErr error, classifier func(curErr, topErr error) error, )
| 276 | // with `true` to indicate something was found. Otherwise this function will return |
| 277 | // `topErr, false`. |
| 278 | func FindWrappedError( |
| 279 | topErr error, |
| 280 | classifier func(curErr, topErr error) error, |
| 281 | ) (error, bool) { |
| 282 | for curErr := topErr; curErr != nil; { |
| 283 | classifiedErr := classifier(curErr, topErr) |
| 284 | if classifiedErr != nil { |
| 285 | return classifiedErr, true |
| 286 | } |
| 287 | |
| 288 | dbxErr, ok := curErr.(DropboxError) |
| 289 | if !ok || dbxErr == nil { |
| 290 | break |
| 291 | } |
| 292 | curErr = dbxErr.Unwrap() |
| 293 | if curErr == nil { |
| 294 | break |
| 295 | } |
| 296 | } |
| 297 | return topErr, false |
| 298 | } |