WithProvider returns a copy of the classification using an explicit provider hint. Explicit provider hints are trusted over provider names heuristically parsed from the error text.
(provider string)
| 84 | // provider hint. Explicit provider hints are trusted over provider names |
| 85 | // heuristically parsed from the error text. |
| 86 | func (c ClassifiedError) WithProvider(provider string) ClassifiedError { |
| 87 | hint := normalizeProvider(provider) |
| 88 | if hint == "" { |
| 89 | return normalizeClassification(c) |
| 90 | } |
| 91 | if c.Provider == hint && strings.TrimSpace(c.Message) != "" { |
| 92 | return normalizeClassification(c) |
| 93 | } |
| 94 | updated := c |
| 95 | updated.Provider = hint |
| 96 | updated.Message = "" |
| 97 | return normalizeClassification(updated) |
| 98 | } |
| 99 | |
| 100 | // WithClassification wraps err so future calls to Classify return |
| 101 | // classified instead of re-deriving it from err.Error(). |