{ data, error, request, response }. API failures are returned in error rather than thrown. The SDK does not add a legacy error hierarchy, runtime validation errors, retries, or caching.
Inspect a result
Check the discriminant before readingdata:
request and response are optional. A request can fail while it is being built or before Fetch produces a response, so do not assume either object exists. When a response exists, use the standard Fetch Response for status and headers; use the generated error payload for operation-specific fields.
Each operation has generated error and response types. For example, getBookById returns GetBookByIdResponses on success and GetBookByIdErrors for documented operation errors. Import those types when an application API needs to expose the generated contract rather than recreating it by hand.
Distinguish failure stages
The sameerror field can represent different failure stages:
- HTTP/API failure:
responseexists andresponse.okis false. The body is parsed as JSON when possible, otherwise text. - Network or Fetch failure:
responseis usually undefined; inspect the thrown value supplied by the host Fetch implementation. - Request construction or serialization failure:
requestmay also be undefined. - Application validation failure: not produced by the SDK; report the application-owned schema error separately.
401 or 403. For 429 and transient 5xx responses, add an application-owned policy that respects server guidance and whether the operation is safe to repeat.
Use unwrap as the throwing boundary
unwrap returns the generated data or throws KomgaApiError when error is present or the response is not successful:
KomgaApiError exposes body, optional status, optional request, and optional response. Its message is a generic status message; inspect body for the generated API error payload. unwrap does not transform network errors into a second SDK hierarchy.
An unwrap(undefined) call throws a plain Error because no result was returned. Successful void operations return undefined through unwrap:
Handle status codes in your application
The generated response gives you the standard FetchResponse, so status handling stays explicit:
unwrap and catch KomgaApiError at the boundary instead of recreating an SDK error hierarchy.
Binary and text failures
The generated client can parse successful responses as JSON, text, blobs, array buffers, form data, or streams. An error response is still parsed as an API error/text body, so do not assume a failed media request has aBlob in error:
Add application policies explicitly
The core package uses native Fetch and has no default retries, response caching, timeout wrapper, or runtime validation. If your application needs those policies, compose them around generated operations or provide a customfetch implementation through createKomgaClient. Keep policy errors in your application’s error model.
catch should preserve the original error and status rather than replacing every failure with an indistinguishable message.
Next steps
Direct API functions
See the flat operation signatures.
Runtime validation
Add consumer-owned runtime schemas.
Request customization
Observe low-level request lifecycles.