Skip to content

Error Handling

Error Response Format

All errors return a JSON body:

json
{
  "error": "Human-readable description"
}

Status Codes

400 Bad Request

Missing or invalid parameters.

json
{ "error": "organisation_id is required" }

401 Unauthorized

No valid session. Log in first.

json
{ "error": "Unauthorized" }

402 Payment Required

Usage limit exceeded for your subscription tier.

json
{ "error": "Project limit reached (1). Upgrade your plan to create more projects." }

403 Forbidden

Authenticated but insufficient permissions (wrong role).

json
{ "error": "Permission denied" }

404 Not Found

Resource doesn't exist or you don't have access to it.

json
{ "error": "Not found" }

500 Internal Server Error

Unexpected server error. Check Vercel logs.

json
{ "error": "Failed to retrieve session" }

Handling Errors

typescript
const response = await fetch('/api/export/risks?organisation_id=...')

if (!response.ok) {
  const { error } = await response.json()
  console.error('API error:', error)
  // Handle based on response.status
}