Skip to main content

Overview

Every error response from the folksbase API follows a consistent JSON shape. This makes it straightforward to build error handling in your client — you always know what to expect.

Error Shape

The code field is stable and safe to use in programmatic checks. The message field is for display purposes and may change between releases.

Error Codes

Validation Errors

When a request fails Zod validation, the details field contains the array of Zod issues. Each issue describes exactly which field failed and why:
The path array tells you which field caused the error. Nested fields use dot-separated paths (e.g., ["custom_fields", "department"]).

Authentication Errors

Auth errors always return 401 with the UNAUTHORIZED code. The message varies depending on the cause:

How Errors Are Handled

The API uses a global error handler middleware. Route handlers don’t catch errors themselves — they let exceptions propagate to the middleware, which formats them consistently. The middleware handles three categories:
  1. Zod errors — caught by instanceof ZodError, returned as 400 with validation details
  2. Auth errors — detected by message content ("Unauthorized" or JWT-related), returned as 401
  3. Everything else — logged with stack trace, returned as 500 with a generic message
This means you’ll never see inconsistent error shapes across different endpoints. The format is always { code, message } with an optional details field.

Client Error Handling

A simple pattern for handling API errors:
The frontend already handles transient server errors (502, 503, 504) with automatic retry — one retry after a 1-second delay. Client errors (4xx) are never retried automatically.