Skip to main content

Error Handling

All SDK errors throw AISecSDKException with a typed errorType property. Transport failures also carry facts that callers can use without parsing the message:

PropertyMeaning
failureKind'http' when AIRS returned a response; 'network' when fetch rejected
statusCodeActual HTTP response status; absent for network failures
retryAfterMsValid server retry guidance normalized to milliseconds

Configuration and response-validation errors leave these transport fields undefined. The metadata does not contain credentials, request payloads, URLs, authorization headers, or raw response bodies.

Error Types

ErrorTypeValueWhen
SERVER_SIDE_ERRORAISEC_SERVER_SIDE_ERROR5xx responses from the API
CLIENT_SIDE_ERRORAISEC_CLIENT_SIDE_ERROR4xx responses / network failures
USER_REQUEST_PAYLOAD_ERRORAISEC_USER_REQUEST_PAYLOAD_ERRORInvalid input (bad UUID, oversized content)
MISSING_VARIABLEAISEC_MISSING_VARIABLEMissing required config (API key, client ID)
AISEC_SDK_ERRORAISEC_SDK_ERRORInternal SDK errors
OAUTH_ERRORAISEC_OAUTH_ERROROAuth2 token fetch failures
RESPONSE_VALIDATIONAISEC_RESPONSE_VALIDATION2xx response body failed Zod validation or JSON parsing

Usage

import { AISecSDKException, ErrorType } from '@cdot65/prisma-airs-sdk';

try {
await scanner.asyncScan(batch, { numRetries: 0 });
} catch (err) {
if (err instanceof AISecSDKException) {
if (err.failureKind === 'http' && err.statusCode === 429) {
console.error(`Rate limited; server delay is ${err.retryAfterMs ?? 'unspecified'}ms`);
return;
}
if (err.failureKind === 'network') {
console.error('Network failure; an async POST may have reached AIRS:', err.message);
return;
}

switch (err.errorType) {
case ErrorType.SERVER_SIDE_ERROR:
console.error('Server error — retry later:', err.message);
break;
case ErrorType.CLIENT_SIDE_ERROR:
console.error('Bad request:', err.message);
break;
case ErrorType.USER_REQUEST_PAYLOAD_ERROR:
console.error('Invalid input:', err.message);
break;
case ErrorType.MISSING_VARIABLE:
console.error('Missing config:', err.message);
break;
case ErrorType.OAUTH_ERROR:
console.error('Auth failed:', err.message);
break;
case ErrorType.RESPONSE_VALIDATION:
console.error('API response shape changed:', err.message);
break;
}
}
}

Retry Behavior

The SDK automatically retries on transient errors:

  • Status codes: 500, 502, 503, 504
  • Network failures: Retried within the same retry budget
  • 429: Not retried automatically; valid Retry-After header guidance takes precedence over the AIRS JSON retry_after.interval / unit fields and is exposed as retryAfterMs
  • Backoff: Exponential with full jitter (uniform [0, 2^attempt × 1000ms])
  • Max retries: Configurable 0-5, default 5
  • Scanner per-call override: Pass { numRetries } to any Scanner operation; 0 means one total fetch attempt, and an omitted value preserves the global setting
  • 401/403 handling: Management/Model Security/Red Team clients automatically refresh the OAuth token and retry once on 401 or 403 responses

For async POSTs, a terminal network error or 5xx response is an ambiguous outcome: AIRS may have accepted the request. The SDK does not claim exactly-once submission and does not expose a generic retryable flag because retry safety depends on the operation. Polling GETs are idempotent; async submission is not known to be.