Skip to content

Error Handling ​

The OneFive API uses standard HTTP status codes and returns structured JSON error responses. Every error includes a machine-readable code and a human-readable message.

Error response format ​

json
{
  "error": {
    "code": "not_found",
    "message": "Product does not exist."
  }
}
FieldTypeDescription
codestringMachine-readable error identifier (see table below).
messagestringHuman-readable explanation.
fieldstringThe specific field that caused the error (when applicable).
detailsarrayPer-field validation errors (for validation_error only).

Status codes ​

400 Bad Request ​

The request is malformed or contains invalid data.

invalid_request - a specific field or parameter is invalid:

json
{
  "error": {
    "code": "invalid_request",
    "message": "Quantity must be greater than zero.",
    "field": "quantity"
  }
}

validation_error - multiple fields failed validation:

json
{
  "error": {
    "code": "validation_error",
    "message": "Request body has invalid fields.",
    "details": [
      { "field": "title", "message": "Required" },
      { "field": "price", "message": "Must be a positive integer" }
    ]
  }
}

401 Unauthorized ​

The API key is missing, malformed, or revoked.

json
{
  "error": {
    "code": "unauthorized",
    "message": "Missing or invalid API key."
  }
}

403 Forbidden ​

The API key does not have permission for this operation. Common causes:

  • Using a publishable key (pk_*) on a write endpoint
  • Key permissions restrict this resource scope
json
{
  "error": {
    "code": "forbidden",
    "message": "Key does not have permission for this action."
  }
}

404 Not Found ​

The requested resource does not exist, or it belongs to a different project.

json
{
  "error": {
    "code": "not_found",
    "message": "Product does not exist."
  }
}

409 Conflict ​

The request conflicts with the current state. For example, creating a product with a handle that already exists:

json
{
  "error": {
    "code": "conflict",
    "message": "A product with this handle already exists."
  }
}

429 Too Many Requests ​

Rate limit or monthly quota exceeded. Check the Retry-After header.

rate_limited - per-minute rate limit exceeded:

json
{
  "error": {
    "code": "rate_limited",
    "message": "Too many requests."
  }
}

quota_exceeded - monthly request quota exhausted:

json
{
  "error": {
    "code": "quota_exceeded",
    "message": "Monthly API quota exceeded."
  }
}

500 Internal Server Error ​

An unexpected error occurred on the server. If this persists, contact support.

json
{
  "error": {
    "code": "internal_error",
    "message": "An unexpected error occurred."
  }
}

Error codes reference ​

CodeStatusWhen it occurs
invalid_request400A field value is invalid or missing
validation_error400Multiple request body fields failed validation
unauthorized401Missing, malformed, or revoked API key
forbidden403Insufficient permissions for this operation
not_found404Resource does not exist or is in a different project
conflict409Unique constraint violation (duplicate handle, etc.)
rate_limited429Per-minute request limit exceeded
quota_exceeded429Monthly API request quota exhausted
internal_error500Unexpected server error

Handling errors in code ​

With the SDK ​

The SDK throws typed errors that you can catch and inspect:

typescript
import { createClient, HydraNotFoundError, HydraRateLimitError } from '@onefive/hydra'

const hydra = createClient({ apiKey: 'sk_...' })

try {
  const product = await hydra.products.get('prod_nonexistent')
} catch (err) {
  if (err instanceof HydraNotFoundError) {
    console.log('Product not found')
  } else if (err instanceof HydraRateLimitError) {
    // Back off and retry
    console.log('Rate limited, retrying...')
  } else {
    throw err
  }
}

With fetch ​

typescript
const res = await fetch('https://api.hydrajs.dev/v1/products/prod_nonexistent', {
  headers: { Authorization: `Bearer ${SECRET_KEY}` }
})

if (!res.ok) {
  const { error } = await res.json()
  console.error(`${error.code}: ${error.message}`)

  if (error.code === 'rate_limited') {
    const retryAfter = res.headers.get('Retry-After')
    // Wait and retry
  }
}

Idempotency ​

For POST requests that create resources, you can include an Idempotency-Key header to safely retry failed requests without creating duplicates:

bash
curl -X POST https://api.hydrajs.dev/v1/products \
  -H "Authorization: Bearer sk_your_key" \
  -H "Idempotency-Key: unique-request-id-123" \
  -H "Content-Type: application/json" \
  -d '{"title": "Classic T-Shirt"}'

If a request with the same idempotency key was already processed, the API returns the original response. Keys expire after 24 hours.

Best practices ​

  • Check error.code, not error.message. Messages may change; codes are stable.
  • Handle 429 with backoff. Respect the Retry-After header to avoid cascading failures.
  • Use idempotency keys for any POST that creates resources.
  • Log the full error response including field and details for debugging validation failures.