Skip to main content

Error Handling

All Tanqory API errors follow a consistent JSON format.

Error Response Format​

{
"statusCode": 422,
"message": "Product title is required",
"error": "Unprocessable Entity",
"code": "VALIDATION_ERROR"
}
FieldDescription
statusCodeHTTP status code
messageHuman-readable error description
errorHTTP status text
codeMachine-readable error code

HTTP Status Codes​

CodeMeaningWhen
400Bad RequestMalformed request body or parameters
401UnauthorizedMissing or expired token
403ForbiddenInsufficient permissions
404Not FoundResource does not exist
409ConflictDuplicate entry (e.g., duplicate SKU)
422Unprocessable EntityValidation failed
429Too Many RequestsRate limit exceeded
500Internal Server ErrorServer-side failure

Error Codes​

CodeDescription
VALIDATION_ERRORRequest body failed Zod validation
RESOURCE_NOT_FOUNDReferenced ID does not exist
DUPLICATE_ENTRYUnique constraint violated
INSUFFICIENT_STOCKNot enough inventory for operation
PAYMENT_FAILEDPayment processor rejected the charge
RATE_LIMIT_EXCEEDEDToo many requests
SUBSCRIPTION_REQUIREDFeature requires a higher plan

SDK Error Classes​

import { TanqoryAPIError, TanqoryRateLimitError, TanqoryNetworkError } from '@tanqory/sdk'

try {
await tanqory.products.create(storeId, data)
} catch (error) {
if (error instanceof TanqoryRateLimitError) {
console.log(`Retry after ${error.retryAfter}s`)
} else if (error instanceof TanqoryNetworkError) {
console.log('Network issue — check connectivity')
} else if (error instanceof TanqoryAPIError) {
console.log(error.statusCode) // 400, 404, 422, etc.
console.log(error.code) // 'VALIDATION_ERROR'
console.log(error.message) // 'Product title is required'
}
}

Retry Logic​

The SDK auto-retries on 429 and 5xx errors (up to maxRetries, default 3):

const tanqory = createClient({
apiKey: 'pk_live_...',
maxRetries: 3, // Retries 429 and 5xx with exponential backoff
})

For manual retry with raw HTTP:

# Check the Retry-After header on 429 responses
HTTP/1.1 429 Too Many Requests
Retry-After: 2
X-RateLimit-Limit: 60
X-RateLimit-Remaining: 0
X-RateLimit-Reset: 1712678400

Validation Errors​

Validation errors may include field-level details:

{
"statusCode": 422,
"message": "Validation failed",
"error": "Unprocessable Entity",
"code": "VALIDATION_ERROR",
"details": [
{ "field": "title", "message": "Product title is required" },
{ "field": "price", "message": "Price must be a positive number" }
]
}