Skip to main content

Overview

The High IQ API uses structured error responses with machine-readable codes and human-readable messages. Every error follows the same envelope format, making client-side error handling consistent and predictable.

Error Response Format

All errors return success: false with a structured error object:

Error Fields

The error.stack field is only included in non-production environments. In production, stack traces are stripped to avoid leaking internal implementation details.

Error Codes

Client Errors (4xx)

Resource-Specific Errors (4xx)

Server Errors (5xx)

Common Error Examples

Not Found

Validation Error

When a request body fails Zod schema validation, the API returns a VALIDATION_ERROR with the full list of validation issues in the details field.

Bad Request

Rate Limit Exceeded

Database Error

In non-production environments, database errors include the underlying error for debugging. In production, they return a generic message.

CommonErrors Helper

The API uses a CommonErrors helper object to generate consistent error responses throughout the codebase. These are the pre-built error factories:

Custom ApiError Class

For route handlers that need to throw errors, the API provides a custom ApiError class:
The global error handler catches ApiError instances and formats them into the standard error response envelope.

Client-Side Handling

TypeScript Type Guard

Use the provided type guards to safely check response types:

HTTP Status Code Handling

Always check the HTTP status code first, then parse the response body for details: