| 106 | } |
| 107 | |
| 108 | func (e *APIError) Error() string { |
| 109 | var b strings.Builder |
| 110 | fmt.Fprintf(&b, "decision: provider returned %d", e.StatusCode) |
| 111 | if e.ErrorType != "" { |
| 112 | fmt.Fprintf(&b, " (%s)", e.ErrorType) |
| 113 | } |
| 114 | fmt.Fprintf(&b, ": %s", e.Body) |
| 115 | if e.BodyReadErr != nil { |
| 116 | fmt.Fprintf(&b, " [response body read failed partway: %v]", e.BodyReadErr) |
| 117 | } |
| 118 | return b.String() |
| 119 | } |
| 120 | |
| 121 | // Unwrap exposes a partial-read failure to errors.Is and errors.As, so a |
| 122 | // caller cancelling mid-read sees errors.Is(err, context.Canceled) rather |