Errors and retries
The one error type, its eleven codes and what to do about each, and when Fieldwork repeats a failed request for you.
Every failure is a FieldworkError, with a code from the table below and whether repeating can succeed.
import { FieldworkError } from "@howells/fieldwork-sdk";
try {
await web.crawl("https://frame.work");
} catch (error) {
if (error instanceof FieldworkError) {
error.code; // "RateLimited"
error.retryable; // true
error.retryAfter; // 30
}
}
Codes
| Code | What happened | What to do |
|---|---|---|
Unsupported |
The provider does not offer this capability. | Use an adapter that does. Nothing was sent. |
Unauthorized |
The key is missing, wrong or not allowed. | Fix the key. Repeating does not help. |
RateLimited |
A rate or plan limit was reached. | Wait retryAfter seconds, then repeat. |
NotFound |
The page, product or job does not exist. | Check the URL or id. |
InvalidRequest |
The input was refused, by Fieldwork or by the provider. | Correct the input; the message says what is wrong. |
JobFailed |
The job ended without a result. | Start a new job if needed; resuming fails again. |
Timeout |
The call or job outlasted its time. | With jobId, pass it as resume. Without one, repeat when retryable is true. |
Aborted |
signal cancelled the call. |
With jobId, the job may still be running; pass it as resume. |
TooLarge |
A downloaded file is larger than maxBytes or the provider’s ceiling. |
Raise maxBytes, up to the ceiling, or use a provider with a higher one. |
NotAFile |
A download reached a web page (HTML), not a file. | Use read for pages. |
ProviderError |
Any other provider failure. | Repeat when retryable is true (5xx and network failures). |
An error with a jobId is never retryable, because repeating the call would start and charge for a second job. Pass the id as resume instead; see Long jobs. Nor is a failure, other than a rate limit, of the request that starts a job, session or monitor: the provider may already have started it, so check before repeating.
What it carries
code, one of the codes above;providerand the HTTPstatus;retryable: whether repeating the same call can succeed;retryAfter, in seconds, when the provider sent one;jobId, when a job had already started;meta, when the provider billed the call before it failed: the usage it reported, in the shape a result’smetahas, such asmeta.usage.creditsfor a Firecrawl download that reached a web page;- the provider’s response, as
cause.
error.toJSON() returns these fields without the provider’s response or meta.
Retries
Fieldwork repeats a request that fails in a way that can succeed on repeat, twice by default, before throwing: a rate limit, a 5xx or a dropped connection. It waits as long as the provider’s retry-after asks, up to 30 seconds, or backs off from half a second with jitter. A provider that asks for a longer wait gets the RateLimited error at once, with retryAfter set.
A request that starts a job, session or monitor, or runs a browser script, is repeated only after a rate limit. After a 5xx the provider may already have started it, and a second attempt could charge twice.
timeout bounds the whole call, retries included, and signal stops the wait between attempts.
Set retries on the adapter for every call, or on one call:
const web = fieldwork({ adapter: exa({ retries: 4 }) }); // every call
await web.search("laptops", { retries: 0 }); // this call onlyFor a model
toolError(error) from @howells/fieldwork-sdk/tools formats any error for a model: the code, the message, whether to retry, and the jobId to resume. See Agent tools.
The HTTP gateway sends the same fields as error in a JSON body, with the HTTP status each code maps to.