Errors

Error response formats and common error codes in the dscr.ai API.

The dscr.ai API uses standard HTTP status codes to indicate the success or failure of requests. Error responses include a consistent JSON body with a machine-readable error code and a human-readable message.

Error Response Format

All error responses follow this structure:

{
  "error": {
    "code": "VALIDATION_ERROR",
    "message": "The request body is invalid.",
    "details": []
  }
}
PropertyTypeDescription
coderequiredstringMachine-readable error code for programmatic handling
messagerequiredstringHuman-readable description of the error
detailsarrayField-level validation errors (for 422 responses)

Error Codes

Handling Errors

import { DscrClient, DscrError } from "@dscr/sdk";

try {
  const deal = await client.deals.get("deal_invalid");
} catch (error) {
  if (error instanceof DscrError) {
    switch (error.code) {
      case "NOT_FOUND":
        console.log("Deal not found");
        break;
      case "RATE_LIMITED":
        await sleep(error.retryAfter);
        break;
      default:
        throw error;
    }
  }
}