Skip to main content

Reference

Error Reference

Complete error taxonomy and handling guide

4 min read


All KLOAKD SDKs share a consistent error hierarchy rooted at KloakdError (Java: KloakdException, with the same names ending in Exception).

Hierarchy

KloakdError
  AuthenticationError       (401)
  PaymentRequiredError      (402)  — the plan's last payment failed
  ForbiddenError            (403)  — not allowed, e.g. another organisation's ID
    NotEntitledError        (403)  — not in the plan (not_entitled, tier_access_denied)
  ConcurrencyLimitError     (409)  — concurrent_limit: all of your plan's work slots stayed in use (a route that cannot queue)
  QuotaExceededError        (429)  — GB allocation and top-ups used up (gb_exhausted)
  RateLimitError            (429)  — too many requests
  UpstreamError             (502)
  BillingUnavailableError   (503)  — usage could not be checked; retry after retry_after
  JobFailedError                   — a handed-off fetch ended in failure
  JobTimeoutError                  — a handed-off request ran past the poll timeout; resume with wait_for_handoff(job_id)
  ApiError                  (other 4xx/5xx, e.g. 404, 422)
    CrawlerTaskNotRunError  (503)  — crawler_task_not_run: a Fetchyr login or form call did not run on a crawler; reason (SDK releases after 0.7.0)

A request still running after about 85 seconds is answered 202 with a job, which evadr.fetch() follows for you; see Long fetches.

A fetch or extraction that could not get the page raises nothing: the API answers 200 with success: false and the reason in error. Check success on every result. 422 means the request body failed validation, and 502 (UpstreamError) means the request could not be run or handed to a job.

Every metered call (fetch, extraction, crawl, batch, …) holds one of the organisation's work slots while it runs. A call made while all of them are in use is queued, not refused: a fetch or an extraction waits for a slot and, if it is still waiting after about 85 seconds, answers 202 like any long request. A route that cannot answer 202 (starting a crawl, for example) waits 10 seconds and then answers 409 concurrent_limit, which raises ConcurrencyLimitError. It is not retried: wait for a job to end, then try again. When too many requests are already queued the answer is 429 with detail.error queue_full and Retry-After: 30. See concurrent work.

Handling errors

from kloakd.errors import (
    AuthenticationError, KloakdError, PaymentRequiredError, QuotaExceededError, RateLimitError,
)

try:
    result = client.crawl("https://example.com", max_depth=2)
except AuthenticationError:
    print("Invalid API key")
except PaymentRequiredError as e:
    print("Update the payment method:", e.upgrade_url)
except QuotaExceededError as e:
    print("GB allocation used up; buy a top-up or upgrade:", e.upgrade_url)
except RateLimitError as e:
    print(f"Rate limited. Retry after {e.retry_after}s")
except KloakdError as e:
    print(f"Error: {e}")
import { KloakdError, QuotaExceededError, RateLimitError } from 'kloakd-sdk';

try {
  const result = await client.crawl('https://example.com', { maxDepth: 2 });
} catch (e) {
  if (e instanceof QuotaExceededError) console.log('GB allocation used up');
  else if (e instanceof RateLimitError) console.log('Retry after', e.retryAfter);
  else if (e instanceof KloakdError) console.log(e.message);
}
Kloakd client = Kloakd.builder()
    .apiKey(System.getenv("KLOAKD_API_KEY"))
    .organizationId(System.getenv("KLOAKD_ORG_ID"))
    .build();

try {
    SiteCrawlResult r = client.crawl("https://example.com",
        CrawlOptions.builder().maxDepth(2).build());
} catch (RateLimitException e) {
    System.out.printf("Retry after %ds%n", e.getRetryAfter());
} catch (KloakdException e) {
    System.out.println(e.getMessage());
}

Error fields

| Field | Type | Available on | |-------|------|-------------| | status_code | integer | All HTTP errors | | message | string | All errors (a 422 keeps the validation messages) | | code | string | All HTTP errors: the API's detail.error | | retry_after | integer | RateLimitError, BillingUnavailableError | | reset_at | string | RateLimitError | | quota_exhausted, quota_used, quota_limit, upgrade_url | | RateLimitError (a test key's quota; not retried) | | module, feature, current_tier, required_tier | string | NotEntitledError | | upgrade_url | string | NotEntitledError, PaymentRequiredError, QuotaExceededError | | tier | string | QuotaExceededError, ConcurrencyLimitError | | concurrent_limit, active_crawls, active_batches | integer | ConcurrencyLimitError (active_crawls counts crawls and batches; active_requests, the other calls in flight, is on the error from 0.6.0). The limit on batches at once (create and resume a batch job) sends active_batches, the organisation's batches that are pending or running, instead of active_crawls; from 0.7.0 the SDKs put it in active_crawls (activeCrawls, ActiveCrawls) | | job_id | string | JobFailedError, JobTimeoutError |

The names above are Python's. TypeScript uses camelCase properties (statusCode, code, retryAfter, resetAt, quotaExhausted, upgradeUrl, currentTier, concurrentLimit, activeCrawls, jobId), Go exported struct fields (StatusCode, Code, RetryAfter, QuotaExhausted, UpgradeURL, Feature, Tier, …), and Java getters (getStatusCode(), getCode(), getRetryAfter(), isQuotaExhausted(), getUpgradeUrl(), getFeature(), getTier(), getConcurrentLimit(), getJobId()). Go's QuotaExceededError and Java's QuotaExceededException also carry the GB figures (GBUsed, GBLimit, PurchasedGBBalance; getGbUsed(), getGbLimit(), getPurchasedGbBalance()). In Go, errors.As with a *ForbiddenError also matches a NotEntitledError.

Disable retries

client = Kloakd(api_key="...", organization_id="...", max_retries=0)
const client = new Kloakd({ apiKey: '...', organizationId: '...', maxRetries: 0 });
Kloakd client = Kloakd.builder()
    .apiKey("...")
    .organizationId("...")
    .maxRetries(0)
    .build();
Was this page helpful?