Skip to main content

Error Codes

The API uses standard HTTP status codes and returns a consistent JSON error envelope.

Error Response Format

JSON
1{
2 "success": false,
3 "error": {
4 "code": "VALIDATION_ERROR",
5 "message": "Invalid request parameters",
6 "details": {
7 "field": "difficulty",
8 "reason": "must be one of: easy, medium, hard, expert"
9 }
10 }
11}

Error Codes Reference

Authentication (401)

StatusCodeDescriptionResolution
401MISSING_API_KEYNo X-API-Key header providedInclude your tenant API key in the X-API-Key header
401INVALID_API_KEYAPI key is malformed or does not existVerify the key in your dashboard
401TENANT_AUTH_REQUIREDEndpoint requires tenant authenticationAdd a valid X-API-Key header
401MISSING_USER_TOKENUser-scoped endpoint called without X-User-TokenAuthenticate the user and pass the token
401INVALID_USER_TOKENUser token is invalid or expiredRefresh the token via /auth/refresh
401TOKEN_EXPIREDJWT has expiredRefresh using the refresh token
401INVALID_CREDENTIALSWrong email or passwordVerify credentials

Authorization (403)

StatusCodeDescriptionResolution
403TENANT_SUSPENDEDTenant account is suspendedContact support
403TENANT_CANCELLEDTenant subscription cancelledReactivate subscription
403ADMIN_ONLYEndpoint requires admin roleUse an admin account
403INSUFFICIENT_TIERFeature requires a higher planUpgrade your plan
403FEATURE_NOT_AVAILABLEFeature is disabled for this tenantEnable the feature in dashboard settings

Validation (400)

StatusCodeDescriptionResolution
400VALIDATION_ERRORRequest body/params failed validationCheck the details field for specifics

Not Found (404)

StatusCodeDescriptionResolution
404NOT_FOUNDRequested resource does not existVerify the ID or path
404PUZZLE_NOT_FOUNDPuzzle with this ID does not existCheck the puzzle UUID
404USER_NOT_FOUNDUser not found in this tenantRegister the user first via /auth/register

Rate Limiting (429)

StatusCodeDescriptionResolution
429TOO_MANY_REQUESTSRate limit exceededWait for Retry-After seconds then retry

Server Errors (5xx)

StatusCodeDescriptionResolution
500INTERNAL_SERVER_ERRORUnexpected server errorRetry the request; contact support if persistent

Handling Errors with the SDK

TypeScript
1import {
2 ApiError,
3 AuthenticationError,
4 RateLimitError,
5 NotFoundError,
6 ValidationError,
7 ServerError,
8} from '@puzzle-section/sdk';
9
10try {
11 const { data } = await client.puzzles.getById('nonexistent');
12} catch (error) {
13 if (error instanceof RateLimitError) {
14 await new Promise(r => setTimeout(r, error.retryAfter * 1000));
15 } else if (error instanceof NotFoundError) {
16 console.log(error.message); // "Puzzle with ID 'nonexistent' not found"
17 } else if (error instanceof AuthenticationError) {
18 console.error('Check your API key');
19 } else if (error instanceof ValidationError) {
20 console.error('Validation:', error.details);
21 } else if (error instanceof ServerError) {
22 console.error('Server error after retries');
23 } else if (error instanceof ApiError) {
24 console.error(error.code, error.statusCode, error.message);
25 }
26}