Documentation
¶
Index ¶
- func IsRetryableCategory(cat ErrorCategory) bool
- type ErrorCategory
- type ServiceError
- func FailedPrecondition(msg string) *ServiceError
- func FailedPreconditionf(format string, args ...any) *ServiceError
- func InvalidInput(msg string) *ServiceError
- func InvalidInputf(format string, args ...any) *ServiceError
- func NotFoundError(msg string) *ServiceError
- func NotFoundErrorf(format string, args ...any) *ServiceError
- func Wrap(cause error, code codes.Code, msg string) *ServiceError
- func Wrapf(cause error, code codes.Code, format string, args ...any) *ServiceError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsRetryableCategory ¶ added in v0.2.0
func IsRetryableCategory(cat ErrorCategory) bool
IsRetryableCategory returns whether a given error category is worth retrying. Client errors (4xx) are never retried. DNS and TLS errors are generally not retried since they indicate configuration problems. Unexpected status codes are not retried since the server responded -- the issue is a mismatch between the response and the webhook's expected_status_codes.
Types ¶
type ErrorCategory ¶ added in v0.2.0
type ErrorCategory string
ErrorCategory classifies delivery errors for health metrics and retry decisions.
const ( // CategorySuccess indicates no error occurred. CategorySuccess ErrorCategory = "success" // CategoryClientError indicates a 4xx HTTP response. // These are permanent failures that should never be retried // (bad request, unauthorized, forbidden, not found, etc.). CategoryClientError ErrorCategory = "client_error" // CategoryServerError indicates a 5xx HTTP response. // These are temporary server-side failures that should be retried. CategoryServerError ErrorCategory = "server_error" // CategoryTimeout indicates a request or connection timeout. // Retryable - the server may recover. CategoryTimeout ErrorCategory = "timeout" // CategoryDNSError indicates the domain could not be resolved. // Typically persistent - suggests misconfigured webhook URL. CategoryDNSError ErrorCategory = "dns_error" // CategoryTLSError indicates a TLS/SSL handshake failure. // Usually persistent - certificate issues, protocol mismatch, etc. CategoryTLSError ErrorCategory = "tls_error" // CategoryConnectionRefused indicates the target actively refused the connection. // May be temporary (service restarting) or permanent (wrong port). CategoryConnectionRefused ErrorCategory = "connection_refused" // CategoryNetworkError covers other network-level errors: // connection reset, host unreachable, broken pipe, etc. // Typically retryable. CategoryNetworkError ErrorCategory = "network_error" // CategoryRateLimited indicates a 429 Too Many Requests response. // Retryable - the server is temporarily rejecting requests due to rate // limiting. The delivery should be retried after the Retry-After period. CategoryRateLimited ErrorCategory = "rate_limited" // CategoryUnexpectedStatus indicates the HTTP response code did not match // the webhook's configured expected_status_codes. For example, a 201 response // when only 200 is expected. The server responded, but the status is not // considered successful by the webhook's configuration. // Not retryable - the target responded correctly from its perspective; // the mismatch is a configuration or contract issue. CategoryUnexpectedStatus ErrorCategory = "unexpected_status" // CategoryUnknown is used when the error cannot be classified. CategoryUnknown ErrorCategory = "unknown" )
func ClassifyError ¶ added in v0.2.0
func ClassifyError(err error) ErrorCategory
ClassifyError inspects a Go error from an HTTP request and returns the appropriate error category. It unwraps url.Error, net.OpError, and other standard library error types to determine the root cause.
func ClassifyHTTPStatus ¶ added in v0.2.0
func ClassifyHTTPStatus(statusCode int) ErrorCategory
ClassifyHTTPStatus categorizes an HTTP response status code.
type ServiceError ¶ added in v1.0.0
type ServiceError struct {
GRPCCode codes.Code
Msg string
Cause error // underlying error (for server-side logging); nil if not wrapping
}
ServiceError is a client-safe error that carries a gRPC status code. When the gRPC layer encounters a ServiceError (via errors.As), it returns the message directly to the client instead of hiding it behind a generic fallback. This replaces the fragile string-matching allowlist in toGRPCError.
Usage in service/validation code:
return errors.InvalidInput("loopback addresses are not allowed")
return errors.FailedPrecondition("event 'order.created' is inactive")
return errors.Wrap(err, codes.InvalidArgument, "invalid URL")
func FailedPrecondition ¶ added in v1.0.0
func FailedPrecondition(msg string) *ServiceError
FailedPrecondition creates a ServiceError with codes.FailedPrecondition. Use when the operation cannot be performed in the current state (e.g., event is inactive, batch expired, delivery already succeeded).
func FailedPreconditionf ¶ added in v1.0.0
func FailedPreconditionf(format string, args ...any) *ServiceError
FailedPreconditionf creates a ServiceError with codes.FailedPrecondition and a formatted message.
func InvalidInput ¶ added in v1.0.0
func InvalidInput(msg string) *ServiceError
InvalidInput creates a ServiceError with codes.InvalidArgument. Use for validation failures, malformed input, missing required fields.
func InvalidInputf ¶ added in v1.0.0
func InvalidInputf(format string, args ...any) *ServiceError
InvalidInputf creates a ServiceError with codes.InvalidArgument and a formatted message.
func NotFoundError ¶ added in v1.0.0
func NotFoundError(msg string) *ServiceError
NotFoundError creates a ServiceError with codes.NotFound.
func NotFoundErrorf ¶ added in v1.0.0
func NotFoundErrorf(format string, args ...any) *ServiceError
NotFoundErrorf creates a ServiceError with codes.NotFound and a formatted message.
func Wrap ¶
func Wrap(cause error, code codes.Code, msg string) *ServiceError
Wrap creates a ServiceError that wraps an underlying cause. The msg is sent to the client; the cause is only logged server-side.
func (*ServiceError) ClientMessage ¶ added in v1.0.0
func (e *ServiceError) ClientMessage() string
ClientMessage returns the message that is safe to send to the client. This is always Msg, never the cause chain.
func (*ServiceError) Error ¶ added in v1.0.0
func (e *ServiceError) Error() string
func (*ServiceError) Unwrap ¶ added in v1.0.0
func (e *ServiceError) Unwrap() error
Unwrap allows errors.Is/errors.As to inspect the underlying cause.