Forge.ErrorClassifier (Forge v0.1.1)
View SourceClassifies errors as retriable or non-retriable based on retry policy.
Based on ADR-003, determines whether an error should trigger a retry attempt or immediately fail.
Examples
# Retry all errors
policy = Forge.RetryPolicy.new(retriable_errors: :all)
Forge.ErrorClassifier.retriable?(429, policy)
#=> true
# Retry specific HTTP status codes
policy = Forge.RetryPolicy.new(retriable_errors: [429, 500, 503])
Forge.ErrorClassifier.retriable?(429, policy)
#=> true
Forge.ErrorClassifier.retriable?(404, policy)
#=> false
# Retry specific exception types
policy = Forge.RetryPolicy.new(retriable_errors: [RuntimeError, ArgumentError])
Forge.ErrorClassifier.retriable?(%RuntimeError{}, policy)
#=> true
# Retry error tuples with specific atoms
policy = Forge.RetryPolicy.new(retriable_errors: [:timeout, :econnrefused])
Forge.ErrorClassifier.retriable?({:error, :timeout}, policy)
#=> true
Summary
Functions
Classifies an error into a category for telemetry reporting.
Determines if an error is retriable based on the retry policy.
Functions
Classifies an error into a category for telemetry reporting.
Returns an atom representing the error type:
:rate_limit- HTTP 429 or rate limit errors:server_error- HTTP 5xx errors:network_error- Network/connection errors:timeout- Timeout errors:unknown- Unclassified errors
Determines if an error is retriable based on the retry policy.
Returns true if the error should be retried, false otherwise.
Error Types
Supports classification of:
- HTTP status codes (integers like 429, 500, 503)
- Exception structs (like %RuntimeError{})
- Error tuples (like {:error, :timeout})
- Custom error values (matched against policy list)