Skip to main content

Error Handling

Oproto APIs use standard HTTP status codes and return consistent error responses to help you diagnose and handle issues.

Error Response Format

All errors return a JSON response with the following structure:

{
"error": {
"code": "RESOURCE_NOT_FOUND",
"message": "The requested company could not be found",
"details": {
"resourceType": "Company",
"resourceId": "comp_abc123"
},
"requestId": "req_7f8g9h0i1j2k"
}
}
FieldDescription
codeMachine-readable error code
messageHuman-readable description
detailsAdditional context (when available)
requestIdUnique identifier for support requests

HTTP Status Codes

Success Codes

StatusMeaning
200 OKRequest succeeded
201 CreatedResource created successfully
204 No ContentRequest succeeded, no response body

Client Error Codes

StatusMeaningCommon Causes
400 Bad RequestInvalid request formatMalformed JSON, missing required fields
401 UnauthorizedAuthentication failedMissing or invalid access token
403 ForbiddenAccess deniedInsufficient permissions for this resource
404 Not FoundResource doesn't existInvalid ID or deleted resource
409 ConflictResource conflictDuplicate entry, version mismatch
422 Unprocessable EntityValidation failedInvalid field values
429 Too Many RequestsRate limit exceededSee Rate Limiting

Server Error Codes

StatusMeaningAction
500 Internal Server ErrorUnexpected errorRetry with backoff, contact support if persistent
502 Bad GatewayUpstream service errorRetry with backoff
503 Service UnavailableService temporarily downRetry with backoff
504 Gateway TimeoutRequest timed outRetry with backoff

Error Codes Reference

Authentication Errors

CodeDescription
INVALID_TOKENAccess token is malformed or expired
TOKEN_EXPIREDAccess token has expired
INSUFFICIENT_SCOPEToken lacks required permissions
INVALID_CREDENTIALSClient credentials are invalid

Validation Errors

CodeDescription
VALIDATION_ERROROne or more fields failed validation
MISSING_REQUIRED_FIELDA required field was not provided
INVALID_FIELD_VALUEField value doesn't match expected format
FIELD_TOO_LONGField exceeds maximum length

Resource Errors

CodeDescription
RESOURCE_NOT_FOUNDThe requested resource doesn't exist
RESOURCE_ALREADY_EXISTSA resource with this identifier already exists
RESOURCE_DELETEDThe resource has been deleted
RESOURCE_LOCKEDThe resource is locked and cannot be modified

Rate Limiting Errors

CodeDescription
RATE_LIMIT_EXCEEDEDToo many requests in the time window
QUOTA_EXCEEDEDMonthly/daily quota has been reached

Handling Errors

Example Error Handler

async function apiRequest(url, options) {
const response = await fetch(url, options);

if (!response.ok) {
const error = await response.json();

switch (response.status) {
case 401:
// Token expired - refresh and retry
await refreshToken();
return apiRequest(url, options);

case 429:
// Rate limited - wait and retry
const retryAfter = response.headers.get('Retry-After') || 60;
await sleep(retryAfter * 1000);
return apiRequest(url, options);

case 500:
case 502:
case 503:
case 504:
// Server error - retry with exponential backoff
throw new RetryableError(error);

default:
throw new ApiError(error);
}
}

return response.json();
}

Retry Strategy

For transient errors (5xx status codes), implement exponential backoff:

async function retryWithBackoff(fn, maxRetries = 3) {
for (let attempt = 0; attempt < maxRetries; attempt++) {
try {
return await fn();
} catch (error) {
if (!error.retryable || attempt === maxRetries - 1) {
throw error;
}

const delay = Math.min(1000 * Math.pow(2, attempt), 30000);
await sleep(delay + Math.random() * 1000);
}
}
}

Debugging Tips

  1. Check the requestId — Include this when contacting support
  2. Review the details object — Often contains specific field-level errors
  3. Verify your authentication — Most 401/403 errors are token-related
  4. Check rate limit headers — Monitor your usage before hitting limits

Getting Help

If you encounter persistent errors:

  1. Note the requestId from the error response
  2. Check the API Status Page for any ongoing incidents
  3. Contact support with the request ID and reproduction steps