Return worker results and handle errors
Choose success, progress, delay or error outcomes and report the correct platform error code.
Use this contract with worker routing. The callback receives { adapter } and returns Promise<TaskResult>.
Worker results and rate limits
| Result | SDK output in a resumable phase | Meaning |
|---|---|---|
{ status: 'success' } | *_DONE | This phase has no remaining work |
{ status: 'progress' } | *_PROGRESS | Checkpoint and continue in another invocation |
{ status: 'delay', delaySeconds: 30 } | *_DELAYED with wire field delay: 30 | Preserve the cursor and back off |
{ status: 'error', error: { message: '...' } } | *_ERROR | Fail the phase |
Discovery and deletion are non-resumable: progress or delay becomes a phase error. For resumable phases, preserve the next unconsumed cursor before returning progress or delay. The next invocation receives CONTINUE_*; do not reset its cursor.
Parse a source Retry-After as seconds or an HTTP date according to the source API. Return a finite nonnegative delay in seconds; choose a safe fallback when the header is absent or invalid. Do not sleep through an entire backoff inside the worker or translate every HTTP error into a rate limit. The SDK's internal DevRev HTTP client does not implement retry behavior for the connector's external API client.
Special error events
AirSyncErrorCode values are platform control signals, not ordinary error labels. All six codes below disable periodic syncs for the affected sync unit by switching its sync type to manual. Use them only when automatic syncing should stop, not for transient network failures or rate limits.
Set error.code to the matching enum member. DevRev maps it to a standard, translatable platform message rather than displaying your custom error.message.
| Code | When to return it | Standard platform message |
|---|---|---|
EXTERNAL_SYNC_UNIT_DELETED | The external sync unit has been deleted. | External system is permanently inactive or inaccessible. |
EXTERNAL_SYNC_UNIT_DEACTIVATED | The external sync unit has been deactivated. | External system is permanently inactive or inaccessible. |
USER_DELETED | The user associated with the sync has been deleted. This maps to the platform's user-authentication error. | User authentication failed. Please re-authenticate. |
EXTERNAL_SYSTEM_NO_ACCESS | No accessible resource can be found in the source system. | Insufficient access. Could not find accessible resource in the source system. |
EXTERNAL_SYSTEM_NO_PERMISSION | The user lacks a permission required to complete the action. | Insufficient permissions. Could not complete required action. |
HISTORICAL_DATA_EXTRACTION_DONE | Historical extraction has reached the end of the available data. | Ingestion complete. No more data to extract. |
The first five codes produce error-level platform records. HISTORICAL_DATA_EXTRACTION_DONE produces an informational record, even though the worker returns status: 'error'. It also switches the sync unit to manual; it does not merely finish the current extraction window. Use it only after verifying that no earlier source data remains. A transient empty page, permission failure, or rate limit is not historical exhaustion.
Confirm the source condition before choosing a code. For example, a source API may return HTTP 404 because a resource is inaccessible, not because it was deleted. If an unrecoverable failure should fail only the current run without disabling periodic syncs through these control signals, return status: 'error' with a descriptive error.message and omit error.code.
Usage
For example, after confirming that the external sync unit was deleted, return a coded error from the extraction worker:
import { AirSyncErrorCode, processExtractionTask } from "@devrev/airsync-sdk";
processExtractionTask({
task: async () => ({
status: "error",
error: {
code: AirSyncErrorCode.EXTERNAL_SYNC_UNIT_DELETED,
message: "The source project configured for this sync was deleted.",
},
}),
});The SDK logs the custom message for diagnostics, sends exactly ERROR_CODE=<code> as the callback's error.message, and omits the code field from the wire payload. Set error.code rather than putting the bare enum value in error.message or appending details to the wire string; the platform must recognize the whole coded message.
Callback acknowledgment and replay
If callback retries fail, the SDK attempts an error callback with already-uploaded extraction artifacts, without flushing buffered records. That callback can also fail.
A lost acknowledgment can cause replay after an accepted request. A failed callback does not prove an external mutation failed; use the idempotency and reconciliation strategy for ambiguous writes.
Related: Worker routing.
Last updated on