| 1 | package types |
| 2 | |
| 3 | import "fmt" |
| 4 | |
| 5 | // TargetError wraps a failure from one configured notification target. |
| 6 | // |
| 7 | // It is returned by ServiceRouter.Send, SendAsync, and SendItems in the |
| 8 | // per-service error positions. Callers can use errors.As to recover the |
| 9 | // *TargetError and read the URL/ID of the failed target, and errors.Unwrap |
| 10 | // to reach the underlying error. |
| 11 | type TargetError struct { |
| 12 | // URL is the service URL or identifier that failed. |
| 13 | URL string |
| 14 | // Err is the underlying error from the service. |
| 15 | Err error |
| 16 | } |
| 17 | |
| 18 | // Error returns the formatted error message including the target URL. |
| 19 | // |
| 20 | // Returns: |
| 21 | // - string: the formatted error message. |
| 22 | func (e *TargetError) Error() string { |
| 23 | return fmt.Sprintf("%s: %v", e.URL, e.Err) |
| 24 | } |
| 25 | |
| 26 | // Unwrap returns the underlying error wrapped by TargetError. |
| 27 | // |
| 28 | // Returns: |
| 29 | // - error: the wrapped error. |
| 30 | func (e *TargetError) Unwrap() error { |
| 31 | return e.Err |
| 32 | } |