Skip to main content

Error Response Format

When an error occurs, the API returns a consistent error response:
{
  "error": {
    "code": "invalid_request",
    "message": "The request body is missing required field 'email'",
    "details": {
      "field": "email",
      "reason": "required"
    }
  }
}

HTTP Status Codes

Status CodeDescription
200Success
201Created
204No Content (successful deletion)
400Bad Request - Invalid parameters
401Unauthorized - Invalid or missing credentials
403Forbidden - Insufficient permissions
404Not Found - Resource doesn’t exist
409Conflict - Resource already exists
422Unprocessable Entity - Validation error
429Too Many Requests - Rate limit exceeded
500Internal Server Error

Common Error Codes

Authentication Errors

CodeDescription
invalid_tokenThe access token is invalid or expired
missing_tokenNo authorization header provided
insufficient_scopeToken lacks required permissions

Validation Errors

CodeDescription
invalid_requestRequest body is malformed
validation_errorOne or more fields failed validation
missing_fieldRequired field is missing

Resource Errors

CodeDescription
not_foundThe requested resource doesn’t exist
already_existsResource with this identifier already exists
conflictOperation conflicts with current state

Error Handling Best Practices

1

Check Status Code First

Use the HTTP status code to determine the general category of error.
2

Parse Error Response

Extract the error.code and error.message for specific handling.
3

Log Details

Store the full error response for debugging purposes.
4

Display User-Friendly Messages

Translate error codes into messages appropriate for your users.

Example Error Handling

try {
  const response = await fetch('https://api.rntor.com/v1/bookings', {
    method: 'POST',
    headers: {
      'Authorization': `Bearer ${apiSecret}`,
      'X-Client-ID': clientId,
      'Content-Type': 'application/json'
    },
    body: JSON.stringify(bookingData)
  });
  
  if (!response.ok) {
    const error = await response.json();
    
    switch (error.error.code) {
      case 'validation_error':
        // Handle validation errors
        break;
      case 'conflict':
        // Handle booking conflicts
        break;
      default:
        // Handle other errors
    }
  }
} catch (e) {
  // Handle network errors
}