IsMovedError checks if an error is a MovedError, even if wrapped. Returns the error and a boolean indicating if it's a MovedError.
(err error)
| 333 | // IsMovedError checks if an error is a MovedError, even if wrapped. |
| 334 | // Returns the error and a boolean indicating if it's a MovedError. |
| 335 | func IsMovedError(err error) (*MovedError, bool) { |
| 336 | if err == nil { |
| 337 | return nil, false |
| 338 | } |
| 339 | var movedErr *MovedError |
| 340 | if errors.As(err, &movedErr) { |
| 341 | return movedErr, true |
| 342 | } |
| 343 | // Fallback to string checking for backward compatibility |
| 344 | s := err.Error() |
| 345 | if strings.HasPrefix(s, "MOVED ") { |
| 346 | // Parse: MOVED 3999 127.0.0.1:6381 |
| 347 | parts := strings.Split(s, " ") |
| 348 | if len(parts) == 3 { |
| 349 | return &MovedError{msg: s, addr: parts[2]}, true |
| 350 | } |
| 351 | } |
| 352 | return nil, false |
| 353 | } |
| 354 | |
| 355 | // IsAskError checks if an error is an AskError, even if wrapped. |
| 356 | // Returns the error and a boolean indicating if it's an AskError. |