ResourcesAPI Fundamentals

Error Handling

HTTP error codes returned by the Chargeflow API, what causes each one, how to resolve them, and the health check endpoint for verifying your key.

This page explains the HTTP error codes returned by the Chargeflow API, which of them are safe to retry, and how to retry correctly.

Retry safety at a glance

StatusCauseRemedyRetry-safe?
400Malformed JSON, wrong types, missing fieldsFix the request body/paramsNo - fix first
401Missing/invalid x-api-key, bad HMAC signatureFix credentialsNo - fix first
403Key lacks permission for the resource, or key invalidDiagnose via health check (below)No - fix first
404Wrong URL or ID, or resource deletedVerify the URL and IDNo - fix first
429Rate limit exceededBack off and retry; honor Retry-After if presentYes - after waiting
500Unexpected server errorRetry with backoff; contact support with requestId if persistentYes - with backoff
502Temporary gateway/upstream issueRetry with backoff; check the status pageYes - with backoff

GET requests are always safe to repeat. Before retrying a write (POST) request, check whether it succeeded; full idempotency semantics are not published yet - see Idempotency for status.

Request IDs

Every API response includes a requestId field with a unique identifier for that request. Include this requestId when contacting Chargeflow support; it allows the team to locate and diagnose your request quickly.

HTTP error codes

Retry with backoff

Paste-ready retry helpers for the retry-safe statuses (429, 500, 502). Both honor Retry-After when present and fall back to exponential backoff with jitter.

retry.ts
const RETRYABLE = new Set([429, 500, 502])

async function fetchWithRetry(url: string, init: RequestInit = {}, maxAttempts = 5) {
  for (let attempt = 1; ; attempt++) {
    const res = await fetch(url, init)
    if (!RETRYABLE.has(res.status) || attempt === maxAttempts) return res

    const retryAfter = Number(res.headers.get('retry-after'))
    const backoff = 2 ** attempt * 500 + Math.random() * 500 // exponential + jitter
    const waitMs = retryAfter > 0 ? retryAfter * 1000 : backoff
    await new Promise((r) => setTimeout(r, waitMs))
  }
}

Health check endpoint

Use the health check endpoint to verify connectivity and confirm your API key is valid at any time:

Terminal
curl -X GET https://api.chargeflow.io/public/2025-04-01/health-check \
  -H "x-api-key: YOUR_API_KEY"

A 200 response with {"status": "ok"} confirms your key is valid and the API is reachable.

Next steps

Was this page helpful?

On this page