k0rdent AI Docs

Errors

Error handling, status codes, and error response structures

Common error codes and their meanings

The k0rdent API uses standard HTTP status codes and structured error responses to communicate failures clearly.

Error Response Structure

All error responses follow a consistent structure with the discriminated union envelope:

Error Object Fields

FieldTypeDescription
codestringMachine-readable error code
messagestringHuman-readable error description
detailsobjectAdditional context (optional)

HTTP Status Codes

The k0rdent API uses the following HTTP status codes:

CodeUsage
200Success (GET, PATCH, DELETE)
201Created (POST that creates resource)
202Accepted (async operation started)
204No Content (DELETE with no body)
207Multi-Status (bulk operations)
400Bad Request (validation error)
401Unauthorized (no/invalid auth)
403Forbidden (valid auth, no permission)
404Not Found
409Conflict (resource state conflict)
422Unprocessable Entity (semantic error)
429Too Many Requests (rate limited)
500Internal Server Error

Key Patterns

  • Use 202 Accepted for all async operations (BMC, K8s interactions)
  • Use 207 Multi-Status for all batch operations (indicates partial success possible)
  • Use 409 Conflict for invalid state transitions (e.g., provisioning an already-provisioned server)
  • Always include error codes in response body, not just HTTP status

Common Error Codes

The API uses machine-readable error codes in the error.code field:

CodeHTTP StatusDescription
VALIDATION_ERROR400Request validation failed
NOT_FOUND404Resource not found
FORBIDDEN403Insufficient permissions
UNAUTHORIZED401Invalid or missing authentication
CONFLICT409Resource state conflict
INVALID_STATE_TRANSITION409Cannot transition resource to target state
POOL_CAPACITY_EXCEEDED409Not enough resources in pool
QUOTA_EXCEEDED403Organization quota exceeded
BMC_CONNECTION_FAILED500Cannot connect to BMC
INTERNAL_ERROR500Unexpected server error

Error Examples

Validation Error

Not Found Error

Invalid State Transition

Capacity Exceeded

Typed Error Classes

The k0rdent API implementation uses typed error classes for consistency:

AppError

Base error class for all application errors:

ValidationError

Used for request validation failures:

NotFoundError

Used when a resource cannot be found:

ForbiddenError

Used when the user lacks permission:

ConflictError

Used for resource state conflicts:

InvalidStateTransitionError

Used for invalid state transitions:

Bulk Operation Errors

Bulk operations use 207 Multi-Status with per-resource error details:

Note: Bulk operations always return success: true at the top level, with per-resource status in the results array.

Error Handling Best Practices

For API Consumers

  • Check the success field - Use TypeScript discriminated unions for type safety
  • Log requestId - Always log the request ID for debugging
  • Handle specific error codes - Don't rely solely on HTTP status codes
  • Parse details field - Provides additional context for validation errors
  • Implement retries - For 500 and 429 errors with exponential backoff

Example Client Code

Rate Limiting

Rate limit errors return 429 Too Many Requests with a Retry-After header indicating when to retry.

Check the Retry-After response header for the recommended retry delay in seconds.

Last updated on

How is this guide?

On this page