Errors

Understanding error responses and how to handle them.

Error Handling

The BugToMe API uses standard HTTP status codes to indicate the success or failure of requests. All error responses include a JSON body with details about the error.

HTTP Status Codes

Code Status Description
200 OK Request succeeded
201 Created Resource created successfully
400 Bad Request Invalid request body or parameters
401 Unauthorized Missing or invalid API token
403 Forbidden Token doesn't have permission for this action
404 Not Found Resource doesn't exist
422 Unprocessable Entity Validation errors
429 Too Many Requests Rate limit exceeded
500 Internal Server Error Something went wrong on our end

Error Response Format

All error responses follow a consistent format:

{
  "error": "Error Type",
  "message": "Human-readable description of the error",
  "details": {}  // Optional additional information
}

Common Errors

Authentication Error (401)

{
  "error": "Unauthorized",
  "message": "Invalid or expired API token"
}

Solution: Check that your API token is correct and hasn't been revoked.

Permission Error (403)

{
  "error": "Forbidden",
  "message": "You don't have permission to access this resource"
}

Solution: Ensure your token has access to the requested organization/project.

Validation Error (422)

{
  "error": "Validation Failed",
  "message": "The request could not be processed due to validation errors",
  "details": {
    "title": ["can't be blank"],
    "given": ["can't be blank", "is too short (minimum is 10 characters)"]
  }
}

Solution: Review the details object and fix the validation issues.

Rate Limit Error (429)

{
  "error": "Rate Limit Exceeded",
  "message": "Too many requests. Please try again later.",
  "details": {
    "retry_after": 3600
  }
}

Solution: Wait for the time specified in retry_after (in seconds) before making more requests.

Handling Errors in Code

JavaScript Example

async function createTicket(ticketData) {
  const response = await fetch('https://bugto.me/api/v1/tickets', {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer pk_your_token',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({ ticket: ticketData })
  });

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

    switch (response.status) {
      case 401:
        throw new Error('Invalid API token');
      case 422:
        throw new Error(`Validation failed: ${JSON.stringify(error.details)}`);
      case 429:
        throw new Error(`Rate limited. Retry after ${error.details.retry_after}s`);
      default:
        throw new Error(error.message);
    }
  }

  return response.json();
}

Getting Help

If you encounter an error that you can't resolve:

  • Check the error message and details carefully
  • Review the API documentation for the endpoint you're using
  • Contact support with the full error response and request details