Responses: Error Shapes
Use this page to understand the gateway's JSON error surface before wiring client-side handling. The gateway returns structured JSON errors for 401, 403, 404,
Use this page to understand the gateway's JSON error surface before wiring client-side handling. The gateway returns structured JSON errors for 401, 403, 404, and 500 status codes, each with an error field and a human-readable message. Knowing these shapes helps you write consistent error handling in your frontend.
Last reviewed: 2026-03-06
When to use this
Use the CORS and response reference when you need to control how the gateway handles browser cross-origin requests or what shape responses take for static, error, and operational endpoints. CORS is configured globally and applies to all routes unless overridden by an explicit OPTIONS handler.
Key concepts
The CORS block is global -- it applies the same origin, method, and header policy to all routes. Per-route CORS overrides require explicit OPTIONS path entries.
The gateway returns a 204 No Content response for OPTIONS preflight requests automatically. You only need an explicit OPTIONS route if a specific path requires different CORS headers.
Static response routes can return JSON objects, strings, booleans, or null. The gateway serializes the
responsefield as-is and setsContent-Type: application/json.Error responses follow a consistent JSON shape with
errorandmessagefields. 401 errors include details about which JWT check failed (expiry, issuer, audience).The gateway adds a
powered-byresponse header by default. This can be useful for debugging which gateway version handled a request.
Repo-grounded example
{
"authorizer": {
"type": "jwt",
"secret": "$env.JWT_SECRET",
"algorithm": "HS256",
"issuer": "https://issuer.example.com",
"audience": "api-audience"
},
"paths": [
{
"method": "GET",
"path": "/private",
"auth": true,
"response": { "private": true }
}
]
}This snippet includes an auth: true route that returns a 401 JSON error if the bearer token is missing, expired, or fails issuer/audience validation. The error body includes which specific check failed, such as "token expired" or "invalid audience".
Troubleshooting
If the browser shows a CORS error, check that
allow_originsincludes the exact origin (scheme + domain + port) your frontend uses -- wildcards are not supported whenallow_credentialsis true.If preflight requests return 404 instead of 204, verify that the global CORS block is present in your config and that no explicit OPTIONS route is shadowing the default behavior.
If a static response returns
nullas a string instead of JSON null, make sure theresponsefield is set tonull(no quotes) in the config JSON.If error responses do not include the expected
messagefield, confirm you are testing against a current gateway version -- older versions used a different error shape.
Related docs
Last updated