Skip to main content
When something goes wrong with an API request, the ByDoctor API always responds with a structured JSON error body rather than a plain text message or an empty response. This consistent format makes it straightforward to identify the problem, display a helpful message to users, and decide whether to retry automatically or surface the issue for human attention.

Error Response Format

Every error response has the same top-level shape: an error object containing a machine-readable code, a human-readable message, and an optional details object with additional context specific to the error type.
Build your error-handling logic around error.code, not error.message. Messages are intended for debugging and may be updated without notice, while codes are stable and versioned.

HTTP Status Codes

The API uses standard HTTP status codes to indicate the outcome of every request. Your client should handle status codes at the transport layer before inspecting the error body.

Common Error Codes

The table below lists the error codes you are most likely to encounter across all endpoints. Use these codes to branch your error-handling logic appropriately.

Retry Strategy

Not all errors are worth retrying. The right approach depends on the HTTP status code:
Retry 429 and 5xx errors with exponential backoff. These indicate transient conditions — rate limits or temporary server issues — that are likely to resolve on their own. Start with a 1-second delay and double it on each subsequent retry (e.g. 1s → 2s → 4s → 8s), with a maximum of 3–5 attempts. Respect the Retry-After header when present on 429 responses.Do not retry 4xx errors (except 429). A 400, 401, 403, 404, 409, or 422 response indicates a problem with your request that will not resolve by repeating it. Fix the underlying issue in your code or data before sending another request.

Validation Errors

When a request fails field-level validation (HTTP 422), the details object includes a fields array. Each entry in the array identifies the specific field that failed and explains why, so you can map errors directly to form inputs or log them for debugging.
Each object in the fields array has the following structure:
When displaying validation errors to your users, use the field names to map errors back to the appropriate UI inputs. Do not expose the raw message strings from the API — write user-friendly copy specific to your application.