fegura.ai

Errors

The Fegura API uses standard HTTP status codes and returns consistent JSON error responses. This page documents the error format and common error codes.

Error Response Format

All error responses follow this structure:

{
  "success": false,
  "error": {
    "code": "ERROR_CODE",
    "message": "Human-readable error description",
    "details": []
  }
}

Error Fields

FieldTypeDescription
successbooleanAlways false for error responses
error.codestringMachine-readable error code for programmatic handling
error.messagestringHuman-readable description of the error
error.detailsarray | undefinedValidation error details (present on Zod validation failures)

HTTP Status Codes

The API uses standard HTTP status codes to indicate request outcomes:

CodeMeaningDescription
200OKRequest succeeded
201CreatedResource created successfully
400Bad RequestInvalid request format or parameters
401UnauthorizedMissing or invalid API key
403ForbiddenInsufficient permissions or scope
404Not FoundResource doesn't exist
409ConflictResource conflict (e.g., duplicate)
500Internal Server ErrorSomething went wrong on our end

Error Codes

Use the error.code field to programmatically handle specific error conditions:

CodeHTTPDescription
UNAUTHORIZED401API key is missing, invalid, or expired
FORBIDDEN403API key doesn't have required scope
NOT_FOUND404Requested resource doesn't exist
BAD_REQUEST400Malformed request or invalid parameters
VALIDATION_ERROR400Request body or parameters failed validation
CONFLICT409Resource already exists or conflicts with current state
INVALID_API_VERSION400The Fegura-Version header contains an unrecognized version
INTERNAL_ERROR500Server error; contact support if persistent

Error Handling Examples

Validation Error

// Request with invalid region
POST /api/scans
{
  "awsAccountId": "550e8400-e29b-41d4-a716-446655440000",
  "region": "invalid-region"
}

// Response (400)
{
  "success": false,
  "error": {
    "code": "VALIDATION_ERROR",
    "message": "Validation failed",
    "details": [
      {
        "path": ["region"],
        "message": "Invalid region. Must be a valid AWS region code."
      }
    ]
  }
}

Resource Not Found

// Request for non-existent resource
GET /api/accounts/550e8400-e29b-41d4-a716-000000000000

// Response (404)
{
  "success": false,
  "error": {
    "code": "NOT_FOUND",
    "message": "AWS Account not found"
  }
}

Best Practices

  • Check success first - Always check the success field before processing response data.
  • Handle errors by code - Use error.code for programmatic handling, not the message text.
  • Implement retries - For 5xx errors, implement exponential backoff with jitter.
  • Log errors - Log the full error response for debugging, including request ID if available.
  • Show user-friendly messages - Use error.message for user-facing error displays.