Error handling
By default, only server errors (HTTP 5XX) and too many requests (HTTP 429) will be retried up to 5 times with exponential backoff. Other HTTP errors will result in a failed read.
Other behaviors can be configured through the Requester
's error_handler
field.
Schema:
ErrorHandler:
type: object
description: "Error handler"
anyOf:
- "$ref": "#/definitions/DefaultErrorHandler"
- "$ref": "#/definitions/CompositeErrorHandler"
Default error handler
Schema:
DefaultErrorHandler:
type: object
required:
- max_retries
additionalProperties: true
properties:
"$parameters":
"$ref": "#/definitions/$parameters"
response_filters:
type: array
items:
"$ref": "#/definitions/HttpResponseFilter"
max_retries:
type: integer
default: 5
backoff_strategies:
type: array
items:
"$ref": "#/definitions/BackoffStrategy"
default: []
Defining errors
From status code
Response filters can be used to define how to handle requests resulting in responses with a specific HTTP status code. For instance, this example will configure the handler to also retry responses with 404 error:
Schema:
HttpResponseFilter:
type: object
required:
- action
additionalProperties: true
properties:
"$parameters":
"$ref": "#/definitions/$parameters"
action:
"$ref": "#/definitions/ResponseAction"
http_codes:
type: array
items:
type: integer
default: []
error_message_contains:
type: string
predicate:
type: string
ResponseAction:
type: string
enum:
- SUCCESS
- FAIL
- IGNORE
- RETRY
Example:
requester:
<...>
error_handler:
response_filters:
- http_codes: [ 404 ]
action: RETRY
Response filters can be used to specify HTTP errors to ignore. For instance, this example will configure the handler to ignore responses with 404 error:
requester:
<...>
error_handler:
response_filters:
- http_codes: [ 404 ]
action: IGNORE
From error message
Errors can also be defined by parsing the error message. For instance, this error handler will ignore responses if the error message contains the string "ignorethisresponse"
requester:
<...>
error_handler:
response_filters:
- error_message_contains: "ignorethisresponse"
action: IGNORE
This can also be done through a more generic string interpolation strategy with the following parameters:
- response: the decoded response
This example ignores errors where the response contains a "code" field:
requester:
<...>
error_handler:
response_filters:
- predicate: "{{ 'code' in response }}"
action: IGNORE
The error handler can have multiple response filters. The following example is configured to ignore 404 errors, and retry 429 errors:
requester:
<...>
error_handler:
response_filters:
- http_codes: [ 404 ]
action: IGNORE
- http_codes: [ 429 ]
action: RETRY
Backoff Strategies
The error handler supports a few backoff strategies, which are described in the following sections.
Schema:
BackoffStrategy:
type: object
anyOf:
- "$ref": "#/definitions/ExponentialBackoffStrategy"
- "$ref": "#/definitions/ConstantBackoffStrategy"
- "$ref": "#/definitions/WaitTimeFromHeader"
- "$ref": "#/definitions/WaitUntilTimeFromHeader"