Types
Shared types used across the core API and adapters are documented here. Types that belong to a specific feature are documented with that feature:
API responses
ApiValidationErrors
The default validation-error shape, keyed by field name.
type ApiValidationErrors = Record<string, string[]>ApiSuccessResponse
A generic successful API response envelope.
interface ApiSuccessResponse<T> {
data: T
}ApiErrorResponse
An API error response containing a message and optional validation errors.
interface ApiErrorResponse<TValidationErrors = ApiValidationErrors> {
message: string
errors?: TValidationErrors
}ApiErrorResponseLike
The response data accepted by createApiErrorFromResponse.
interface ApiErrorResponseLike {
status: number
statusText?: string
body?: unknown
}Error classification
For the difference between broad error types and specific error kinds, see Error Kinds.
OkapiErrorType
A union of the presentation-level values from OKAPI_ERROR_TYPE.
type OkapiErrorType =
(typeof OKAPI_ERROR_TYPE)[keyof typeof OKAPI_ERROR_TYPE]OkapiErrorSource
A union of the origin values from OKAPI_ERROR_SOURCE. See OkapiError.source for the meaning of each value.
type OkapiErrorSource =
(typeof OKAPI_ERROR_SOURCE)[keyof typeof OKAPI_ERROR_SOURCE]Error data
OkapiErrorParams
The values accepted by the OkapiError constructor.
interface OkapiErrorParams<
TCustomKind extends string = never,
TValidationErrors = ApiValidationErrors,
> {
kind: OkapiErrorKind<TCustomKind>
message: string
source?: OkapiErrorSource
statusCode?: number
statusText?: string
validationErrors?: TValidationErrors
raw?: unknown
cause?: unknown
}MappedOkapiError
The presentation-friendly error returned by Okapi error mappers.
interface MappedOkapiError<
TCustomKind extends string = never,
TValidationErrors = ApiValidationErrors,
> {
type: OkapiErrorType
title: string
message: string
details: OkapiError<TCustomKind, TValidationErrors>
errors?: TValidationErrors
}OkapiErrorMapper
A function that maps an unknown thrown value to a presentation-friendly error.
type OkapiErrorMapper<
TCustomKind extends string = never,
TValidationErrors = ApiValidationErrors,
> = (error: unknown) => MappedOkapiError<TCustomKind, TValidationErrors>ValidationErrorsParser
A function that validates or transforms an unknown validation payload.
type ValidationErrorsParser<TValidationErrors> = (
value: unknown,
) => TValidationErrors | undefinedSee Custom Validation Errors for parser behavior and examples.
Configuration
OkapiErrorOptions
Shared options accepted by the core API and adapter mapper factories. Use resolveKind to customize error classification, i18n to customize presentation text, and parseValidationErrors when your API uses a different validation-error shape.
interface OkapiErrorOptions<
TCustomKind extends string = never,
TValidationErrors = ApiValidationErrors,
> {
i18n?: OkapiErrorI18nOptions<TCustomKind, TValidationErrors>
resolveKind?: OkapiErrorKindResolver<TCustomKind>
parseValidationErrors?: ValidationErrorsParser<TValidationErrors>
}MapOkapiErrorOptions
The options accepted by mapOkapiError.
interface MapOkapiErrorOptions<
TCustomKind extends string = never,
TValidationErrors = ApiValidationErrors,
> extends OkapiErrorOptions<TCustomKind, TValidationErrors> {}OkapiErrorAdapterOptions
The shared options accepted by the fetch, Axios, and ofetch adapters.
interface OkapiErrorAdapterOptions<
TCustomKind extends string = never,
TValidationErrors = ApiValidationErrors,
> extends OkapiErrorOptions<TCustomKind, TValidationErrors> {}