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
{
"error": {
"code": "not_found",
"message": "Product does not exist."
}
}| Field | Type | Description |
|---|---|---|
code | string | Machine-readable error identifier (see table below). |
message | string | Human-readable explanation. |
field | string | The specific field that caused the error (when applicable). |
details | array | Per-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:
{
"error": {
"code": "invalid_request",
"message": "Quantity must be greater than zero.",
"field": "quantity"
}
}validation_error - multiple fields failed validation:
{
"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.
{
"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
{
"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.
{
"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:
{
"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:
{
"error": {
"code": "rate_limited",
"message": "Too many requests."
}
}quota_exceeded - monthly request quota exhausted:
{
"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.
{
"error": {
"code": "internal_error",
"message": "An unexpected error occurred."
}
}Error codes reference
| Code | Status | When it occurs |
|---|---|---|
invalid_request | 400 | A field value is invalid or missing |
validation_error | 400 | Multiple request body fields failed validation |
unauthorized | 401 | Missing, malformed, or revoked API key |
forbidden | 403 | Insufficient permissions for this operation |
not_found | 404 | Resource does not exist or is in a different project |
conflict | 409 | Unique constraint violation (duplicate handle, etc.) |
rate_limited | 429 | Per-minute request limit exceeded |
quota_exceeded | 429 | Monthly API request quota exhausted |
internal_error | 500 | Unexpected server error |
Handling errors in code
With the SDK
The SDK throws typed errors that you can catch and inspect:
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
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:
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, noterror.message. Messages may change; codes are stable. - Handle
429with backoff. Respect theRetry-Afterheader to avoid cascading failures. - Use idempotency keys for any POST that creates resources.
- Log the full error response including
fieldanddetailsfor debugging validation failures.