Repository navigation
Affonso Errors
Affonso throws one error class, AffonsoError, for configuration,
request validation, vendor responses, transport failures and webhook
verification — see errors/Base.ts and
errors/AffonsoErrorCodes.ts.
import { AffonsoError } from '@tundraconnect/affonso/errors';
declare function callTheClient(): Promise<unknown>;
try {
await callTheClient();
} catch (err) {
if (err instanceof AffonsoError && err.transient) {
// TIMEOUT, NETWORK_ERROR, SERVICE_UNAVAILABLE or RATE_LIMITED: retry later.
} else {
throw err;
}
}Branch on the readonly error.code, never on .message. error.transient
is true exactly for the codes in AFFONSO_TRANSIENT_CODES.
| Code | Meaning |
|---|---|
CONFIG_INVALID_API_KEY |
auth is missing, isn't BEARER, or its token is blank. |
| Code | Meaning |
|---|---|
REQUEST_VALIDATION_ERROR |
A request failed local validation; nothing was sent. reason says which rule. |
RESPONSE_ERROR |
A success body did not match the expected schema, or a verified webhook body is not an Affonso event. |
UNKNOWN_ERROR |
An unmapped status, or an unregistered code was passed to the constructor. |
Affonso answers a failure with an HTTP status and
{ success: false, error: { code, message } }. Classification follows the
status; Affonso's own code is kept as vendorCode.
| Code | HTTP | Typical vendor codes | Transient |
|---|---|---|---|
INVALID_REQUEST |
400, 422 | VALIDATION_ERROR |
no |
AUTH_FAILED |
401 |
MISSING_API_KEY, INVALID_API_KEY_FORMAT, INVALID_API_KEY, API_KEY_DISABLED, API_KEY_EXPIRED
|
no |
FORBIDDEN |
403 | INSUFFICIENT_PERMISSIONS |
no |
NOT_FOUND |
404 |
NOT_FOUND, CLICK_NOT_FOUND
|
no |
CONFLICT |
409 |
DUPLICATE_ERROR (taken tracking id, referral email or coupon code) |
no |
RATE_LIMITED |
429 | RATE_LIMIT_EXCEEDED |
yes |
SERVICE_UNAVAILABLE |
5xx |
INTERNAL_ERROR; a 502 is a payment-provider failure on coupon create/delete |
yes |
A 2xx whose body says success: false is treated as a failure too.
| Code | Meaning | Transient |
|---|---|---|
TIMEOUT |
No answer within timeout seconds (timeoutSeconds context). |
yes |
NETWORK_ERROR |
The request failed before any response (DNS, TLS, connection). | yes |
| Code | Meaning |
|---|---|
WEBHOOK_INVALID_HEADERS |
X-Affonso-Timestamp or X-Affonso-Signature is missing. |
WEBHOOK_TIMESTAMP_INVALID |
The timestamp isn't whole Unix seconds, or is outside the tolerance (300 s). |
WEBHOOK_SIGNATURE_INVALID |
The signature does not match — treat the request as forged. |
WEBHOOK_INVALID_SECRET |
The signing secret is empty. |
The most common cause of WEBHOOK_SIGNATURE_INVALID on a genuine delivery
is a body that was parsed and re-serialized before verification: pass
await req.text(). The second is hex-decoding the secret — use it as-is.
Affonso limits per minute and per second by plan (Launch 300/min and
10/s up to Enterprise 3,000/min and 100/s) and sends X-RateLimit-Limit,
X-RateLimit-Remaining and X-RateLimit-Reset on every response, plus
Retry-After on a 429. trackClick uses its own burst limit.
Read metadata with the public getContextValue(key).
| Key | Present on | Description |
|---|---|---|
vendor |
all | Always 'Affonso'. |
status |
vendor failures | HTTP status code. |
detail |
vendor failures | Vendor message plus its code. |
vendorCode |
documented-envelope failures | Affonso's own error code. |
issues |
some VALIDATION_ERRORs |
Per-field messages. |
body |
vendor failures | The parsed response body. |
retryAfterSeconds |
RATE_LIMITED |
How long Affonso asked you to wait. |
retried |
RATE_LIMITED with maxRetryWait
|
Whether RESTler already waited once. |
reason |
validation / webhook codes | Which rule failed. |
responseError |
validation codes | The Guardian failure, as JSON. |
timeoutSeconds |
TIMEOUT |
The deadline that was missed, in seconds. |
originalCode |
UNKNOWN_ERROR fallback |
The unrecognized code passed in. |
Neither the API key nor the webhook signing secret ever appears in an error's message or context.
retryAfterSeconds is read by RESTler from Retry-After (or the other
standard rate-limit headers); when a 429 carries no header hint, the
retryAfter field of Affonso's error body is used instead. It is
undefined when neither is present — never a guess.
Nothing is retried by default. Opt in with two client options (seconds,
each 0–120):
-
maxRetryWait— when a 429 carries a hint no longer than this, RESTler waits that long and retries once; otherwise it throwsRATE_LIMITEDimmediately, withretried: false. A retry that is throttled again throwsRATE_LIMITEDwithretried: true. -
defaultRetryWait— the wait used when a 429 carries no header hint. Only consulted whenmaxRetryWaitis set, and still capped by it.
Writes are not all idempotent: createConversion is (by
external_event_id), recordSignup is (by click_id), and
createCommission dedupes on payment_intent_id, but createAffiliate,
createReferral and createBonus are not — read before resending one
that timed out.
- Affonso
- Algolia
- AviationWeather
- AzureBlob
- Binance
- CloudflareDNS
- CloudflareEmail
- CloudflareKV
- CloudflareSaaS
- CloudflareTurnstile
- CoinGecko
- Deribit
- Discord
- DodoPayments
- EIA
- GCS
- GoogleAnalytics
- GoogleCertificateManager
- GoogleWebRisk
- Kalshi
- ntfy
- OpenExchange
- OpenMeteo
- OpenWeatherMap
- Paddle
- PayPal
- Polymarket
- Pyth
- Razorpay
- Resend
- S3
- SendGrid
- Sentry
- Slack
- Stripe
- Telegram
- Twilio
- UpstashRedis
- URLhaus