docs/platform/connector-development/connector-builder-ui/error-handling.md
:::warning When using the "Test" button to run a test sync of the connector, the Connector Builder UI will not retry failed requests. This is done to reduce the amount of waiting time in between test syncs. :::
Error handlers allow the connector to decide how to continue fetching data according to the contents of the response from the partner API. Depending on attributes of the response such as status code, text body, or headers, the connector can continue making requests, retry unsuccessful attempts, or fail the sync.
The Connector Builder provides three types of error handlers to handle different scenarios:
When an error handler is not configured for a stream, the connector will default to retrying requests that received a 429 and 5XX status code in the response 5 times using a 5-second exponential backoff. This default retry behavior is recommended if the API documentation does not specify error handling or retry behavior.
Refer to the documentation of the API you are building a connector for to determine how to handle response errors. There can either be a dedicated section listing expected error responses (ex. Delighted) or API endpoints will list their error responses individually (ex. Intercom). There is also typically a section on rate limiting that summarizes how rate limits are communicated in the response and when to retry.
The Default Error Handler is the most commonly used error handler and provides comprehensive configuration options for handling API errors. It consists of three main components:
The Composite Error Handler allows you to chain multiple error handlers together. When a response is received, each error handler in the list is evaluated in sequence until one matches the response. This is useful when you need different error handling logic for different types of failures.
Example use cases:
The Custom Error Handler allows you to implement custom error handling logic through code. This requires specifying a fully-qualified class name that implements the custom error handling behavior. This option is for advanced users who need error handling logic that cannot be achieved through the standard configuration options.
The API documentation will usually cover when to reattempt a failed request that is retryable. This is often through a 429 Too Many Requests response status code, but it can vary for different APIs. The following backoff strategies are supported in the connector builder:
When the API documentation recommends that requests be retried after waiting a constant amount of time, the "Constant" backoff strategy should be set on the error handler.
Configuration:
Examples:
30 (wait 30 seconds)30.5 (wait 30.5 seconds)"{{ config['backoff_time'] }}" (use value from connector configuration)The Intercom API is an API that recommends a constant backoff strategy when retrying requests.
When the API documentation recommends that requests be retried after waiting an exponentially increasing amount of time, the "Exponential" backoff strategy should be set on the error handler.
The exponential backoff strategy uses a multiplicative factor to determine wait times. The interval is calculated as factor * 2^attempt_count. For a backoff strategy with factor set to 5 seconds, when the connector receives an API response that should be retried, it will wait 5 seconds before reattempting the request. Upon receiving subsequent failed responses, the connector will wait 10, 20, 40, and 80 seconds, permanently stopping after a total of 5 retries.
Configuration:
Examples:
5 (uses 5-second base factor)10 (uses 10-second base factor)"{{ config['retry_factor'] or 5 }}" (use config value or default to 5)Note: When no backoff strategy is defined, the connector defaults to using an exponential backoff to retry requests.
The Delighted API is an API that recommends using an exponential backoff. In this case, the API documentation recommends retrying requests after 2 seconds, 4 seconds, then 8 seconds and so on.
Although a lot of API documentation does not call out using an exponential backoff, some APIs like the Posthog API mention rate limits that are advantageous to use an exponential backoff. In this case, the rate limit of 240 requests/min should work for most syncs. However, if there is a spike in traffic, then the exponential backoff allows the connector to avoid sending more requests than the endpoint can support.
The "Wait Time Extracted from Response Header" backoff strategy allows the connector to wait before retrying a request based on the value specified in the API response header.
Configuration:
Examples:
"Retry-After""([-+]?\\d+)" (extracts numeric value)3600 (don't wait more than 1 hour)The Chargebee API documentation recommends using the Retry-After in the response headers to determine when to retry the request.
When running a sync, the connector receives from the Chargebee API a response with a 429 status code and the Retry-After header set to 60. The connector interprets the response retrieving that value from the Retry-After header and will pause the sync for 60 seconds before retrying.
The "Wait Until Time Defined in Response Header" backoff strategy allows the connector to wait until a specific time before retrying a request according to the API response header. This strategy extracts a timestamp from the response header and waits until that time before retrying.
Configuration:
Examples:
"X-RateLimit-Reset"10 (always wait at least 10 seconds)"([-+]?\\d+)" (extracts numeric timestamp)The Recurly API is an API that defines a header X-RateLimit-Reset which specifies when the request rate limit will be reset.
Take for example a connector that makes a request at 25/04/2023 01:00:00 GMT and receives a response with a 429 status code and the header X-RateLimit-Reset set to 1682413200. This epoch time is equivalent to 25/04/2023 02:00:00 GMT. Using the X-RateLimit-Reset header value, the connector will pause the sync for one hour before attempting subsequent requests to the Recurly API.
A response filter should be used when a connector needs to interpret an API response to decide how the sync should proceed. Response filters allow you to define specific conditions that determine whether a response should be retried, ignored, treated as successful, cause the sync to fail, or be treated as rate-limited.
Multiple response filters can be configured for a single error handler. When using multiple filters, they are applied sequentially and the response will be processed according to the first filter that matches.
If a response from the API matches the conditions of the response filter, the connector will continue the sync according to the configured action. The following actions are available:
When using the FAIL action, you can optionally specify a failure type to categorize the error:
The "Error message" field allows you to customize the message that is relayed back to users when the API response matches a response filter. This field supports interpolation, allowing you to include dynamic information from the response in the error message.
Configuration:
Interpolation context available:
config: Access to connector configuration valuesresponse: Access to the API response contentheaders: Access to response headers"API rate limit exceeded. Please try again later.""Invalid API key: {{ response.error_message }}""Request failed with status {{ response.status_code }}: {{ response.message }}"For a response filter that defines the "Error Message Substring" field, the connector will check if the provided text exists within the text body of the API response. If the text is present, the response filter will carry out the specified action.
Configuration:
Example:
"This API operation is not enabled for this site"For the Chargebee API, some endpoints are only available for a specific API version and if an endpoint is unavailable, the response text will contain "This API operation is not enabled for this site". The Airbyte Chargebee integration allows customers to configure which API version to use when retrieving data for a stream. When the connector makes requests to Chargebee using an unsupported version, the response filter will match according to the response text and proceeds based on the configured action.
A response filter can specify a set of numeric HTTP status codes to match against. When receiving an API response, the connector will check if the status code of the response is in the provided set of HTTP status codes.
Configuration:
Examples:
[420, 429] (match rate limiting codes)[500] (match server errors)[403, 404] (match specific client errors)The Pocket API emits API responses for rate limiting errors using a 403 error status code. The default error handler interprets 403 errors as non-retryable and will fail the sync when they are encountered. The connector can configure a response filter with HTTP status codes that contains 403. When a 403 error response from the API is encountered, the connector proceeds based on the configured action.
This field allows for more granular control over how the response filter matches against attributes of an API response. The predicate is an interpolation expression that is evaluated against the API response's text body or headers.
Configuration:
Examples:
"{{ 'Too many requests' in response }}" (check if text exists in response)"{{ response.code == 300 }}" (check specific field value)"{{ 'error_code' in response and response['error_code'] == 'ComplexityException' }}" (complex condition)For the Zoom API, the response text body can include a special non-error status codes under the code field. An example response text body would look like {"code": 300}. The "Error message contains" condition is too broad because there could be record data containing the text "300". Instead, for a response filter defining the predicate as {{ response.code == 300 }}, during a sync, the predicate expression will be evaluated to true and the connector proceeds based on the configured action.
The "Max retry count" field allows you to configure the maximum number of times a request will be retried before giving up. This applies to all retryable responses (those with RETRY or RATE_LIMITED actions).
Configuration:
Examples:
5 (default - retry up to 5 times)0 (no retries)10 (retry up to 10 times for persistent issues)When using a Composite Error Handler, you can chain multiple error handlers together. Each error handler in the list is evaluated in sequence until one matches the response. This allows for sophisticated error handling workflows:
For advanced use cases that cannot be handled through configuration, you can implement a Custom Error Handler. This requires:
Example:
"source_myapi.components.MyCustomErrorHandler"Most APIs implement rate limiting. Here's a recommended approach:
Retry-After header[429]RATE_LIMITEDFor temporary server issues:
[500, 502, 503, 504]RETRYFor known API error conditions:
IGNORE: For expected errors that should not stop the syncFAIL: For configuration errors that require user interventionSUCCESS: For responses that contain valid data despite error status codesIf your error handler is not working as expected: