Skip to main content
API Reference

Error Handling

Understand API error responses, error codes, and how to handle them in your integrations.

Error Response Format

When an API request fails, the response body contains a structured error object:

Error Response Structurejson
{
  "error": {
    "code": "not_found",
    "message": "Tournament not found",
    "details": []
  }
}
FieldTypeDescription
codestringMachine-readable error code (use this for programmatic handling)
messagestringHuman-readable description of the error
detailsarrayAdditional error details (e.g., field-level validation errors)

HTTP Status Codes

The API uses standard HTTP status codes to indicate the success or failure of a request:

Success Codes

StatusMeaningWhen
200OKRequest succeeded (GET, DELETE)
201CreatedResource was successfully created (POST)

Client Error Codes

StatusMeaningWhen
400Bad RequestInvalid request body, missing required fields
401UnauthorizedMissing, invalid, revoked, or expired API key
403ForbiddenAPI key lacks the required scope for this endpoint
404Not FoundResource does not exist or you don't have access
422Unprocessable EntityValidation failed — check the details array
429Too Many RequestsRate limit exceeded — wait and retry

Server Error Codes

StatusMeaningWhen
500Internal Server ErrorSomething went wrong on our end

Error Codes Reference

The code field in error responses uses these machine-readable identifiers:

CodeHTTPDescription
unauthorized401Missing, invalid, expired, or revoked API key
forbidden403API key does not have the required permission scope
not_found404Resource does not exist or is not accessible to this key
validation_error422Request body failed validation
rate_limit_exceeded429Too many requests in the current window
key_limit_reached400Maximum of 10 active API keys per account
database_error500Internal database error (contact support if persistent)
internal_error500Unexpected server error

Validation Errors

When a request body fails validation (422), the details array contains field-level errors:

422 Validation Errorjson
{
  "error": {
    "code": "validation_error",
    "message": "Validation failed",
    "details": [
      {
        "field": "name",
        "message": "String must contain at least 1 character(s)"
      },
      {
        "field": "permissions",
        "message": "Array must contain at least 1 element(s)"
      }
    ]
  }
}

Tip

Always check the details array for validation errors. Each entry includes the field name and a descriptive message.

Handling Errors

Here's a recommended pattern for handling API errors:

Error Handling Examplejavascript
async function callApi(path, options = {}) {
  const res = await fetch(`https://readyraider.com/api/v1${path}`, {
    ...options,
    headers: {
      Authorization: `Bearer ${API_KEY}`,
      "Content-Type": "application/json",
      ...options.headers,
    },
  });

  const body = await res.json();

  if (!res.ok) {
    const error = body.error;
    switch (error.code) {
      case "unauthorized":
        throw new Error("Invalid API key. Check your credentials.");
      case "forbidden":
        throw new Error(`Missing scope: ${error.message}`);
      case "not_found":
        return null; // Resource not found
      case "rate_limit_exceeded":
        const retryAfter = res.headers.get("Retry-After");
        throw new Error(`Rate limited. Retry after ${retryAfter}s`);
      case "validation_error":
        const fields = error.details.map(d => `${d.field}: ${d.message}`);
        throw new Error(`Validation failed: ${fields.join(", ")}`);
      default:
        throw new Error(`API error: ${error.message}`);
    }
  }

  return body.data;
}

Troubleshooting

Getting 401 on every request?

Verify your API key starts with rr_live_ and that you're using Bearer (not Basic) in the Authorization header. Also check that the key hasn't been revoked or expired.

Getting 403 Forbidden?

The error message will tell you which scope is required. Create a new API key with the needed scope, or check that your existing key has the right permissions.

Getting 404 for a resource you know exists?

The API returns 404 for both "not found" and "no access" to prevent resource enumeration. Verify you have the correct ID and that the resource is accessible to the authenticated user.

Getting 500 errors?

Include the X-Request-Id header value when contacting support. This helps us trace the exact request that failed.