Every Lynkow API error has the same JSON body. This page shows it, lists the common status codes, and maps them to the SDK's
LynkowError. Previous: Authentication and Keys | Next: Pagination
Reference - This guide is a tutorial. For exhaustive, always-current signatures and field lists, see the auto-generated reference:
API: Storefront API Overview, where each endpoint lists the codes it returns
SDK: SDK Types
Prerequisites
A first request done (Quick Start)
The error body
A request with a Site ID that is not a UUID:
curl -i "https://api.lynkow.com/storefront/not-a-uuid/contents"returns 400 with this body:
{
"errors": [
{
"message": "Site ID must be a valid UUID",
"code": "TENANT_SITE_ID_INVALID"
}
],
"requestId": "4f1c2a9e-8b7d-4e3f-a5c6-1d2e3f4a5b6c"
}errors: one entry or more. Each has amessage, readable English for logs. Most have acode. A validation error adds afield.code: the stable reason. Branch on it, never onmessage, which can change.requestId: the ID of this request, on most error bodies. Every response carries the same ID in theX-Request-Idheader. Quote it when you contact support.
A validation error returns 422 with one entry per invalid field:
{
"errors": [
{ "message": "The email field must be a valid email address", "field": "email", "code": "VALIDATION_EMAIL" }
],
"requestId": "..."
}Show each message next to its field. The VALIDATION_... code names the rule that failed: use field to place the message, and a 422 status to know the input was refused.
An unexpected server error returns 500 with the message Internal server error, without details.
Status codes
Status | Common codes | What to do |
|---|---|---|
400 |
| Fix the request: here, the Site ID in the URL |
401 |
| Send a valid credential (Authentication and Keys) |
402 | The site's plan or subscription does not allow the operation | |
403 |
| The API token lacks a permission, or a browser call came from a domain the site does not allow |
404 |
| The site or the resource does not exist, or is not published |
409 |
| The resource changed or already exists: reload it and try again |
422 |
| Fix the input shown by |
429 |
| Wait, then retry with a backoff (Rate Limits) |
500 |
| Retry later. Send the |
503 |
| Retry later |
Some endpoints return their own codes, such as TERMS_NOT_ACCEPTED on checkout. The API reference lists them on each endpoint.
With the SDK
Every SDK method rejects with a LynkowError. Use isLynkowError() to narrow it:
import { isLynkowError } from 'lynkow'
import { notFound } from 'next/navigation'
import { lynkow } from '@/lib/lynkow'
export default async function ArticlePage({ params }: { params: Promise<{ slug: string }> }) {
const { slug } = await params
try {
const article = await lynkow.contents.getBySlug(slug)
return <h1>{article.title}</h1>
} catch (error) {
if (isLynkowError(error) && error.code === 'NOT_FOUND') notFound()
throw error
}
}A LynkowError carries:
status: the HTTP status,0when no response arrived.code: the category, from the status:BAD_REQUEST(400),UNAUTHORIZED(401),PAYMENT_REQUIRED(402),FORBIDDEN(403),NOT_FOUND(404),CONFLICT(409),VALIDATION_ERROR(422),TOO_MANY_REQUESTS(429),SERVICE_UNAVAILABLE(503),INTERNAL_ERROR(500 and any other status),NETWORK_ERROR(no response).apiCode: the API'scode, from the first entry oferrorsthat has one.details: theerrorsentries, with theirmessage,fieldandcode.
Branch on code for generic handling, and on apiCode when one status covers several cases. Error Handling & Resilience covers retries, timeouts and the commerce codes.
Reference
Next Steps
Pagination - page through lists with
page,limitandmetaRate Limits - the limits, the headers and how to retry a 429
Error Handling & Resilience - retries, timeouts and error pages in Next.js