Errors
The SDK reports failure in two ways. Calls that talk to the platform return a neverthrow
ResultAsync whose error side is a plain object with a type field, so errors are values you
match on. Programming mistakes and local validation throw ordinary exceptions. This page lists both.
For the platform’s own error envelope and codes, see Errors and Wire conventions.
Result values
Section titled “Result values”const result = await client.eventTypes().list();
result.match( (page) => console.log(page), (error) => { switch (error.type) { case 'not_found': console.error('missing:', error.message); break; case 'validation': console.error(error.errors); break; default: console.error(error.type, error.message); } },);
// or with guardsif (result.isErr()) throw new Error(result.error.message);ok, err, Result and ResultAsync are re-exported from the package root, so you do not need to
import neverthrow yourself.
SdkError
Section titled “SdkError”SdkError is the union of these variants, each with a type and a message:
type |
Extra fields | Produced by |
|---|---|---|
missing_credentials |
Client credentials mode with an empty client id or secret. | |
invalid_credentials |
The token endpoint answered 401 or 403. | |
token_expired |
A 401 from the API (after one automatic refresh in client-credentials mode), or no token available. |
|
token_fetch_failed |
cause? |
The token endpoint failed otherwise, returned no token, or the request itself failed. |
network |
cause? |
fetch threw, or a response body could not be read. |
timeout |
durationMs |
The attempt exceeded the configured timeout and was aborted (see Client). A timeout after the request was sent is retried only for a repeatable request. |
http_error |
status, body? |
Any status not listed below. |
validation |
errors (field to messages) |
HTTP 422. |
not_found |
resource?, id? |
HTTP 404. |
forbidden |
HTTP 403. | |
conflict |
code? |
HTTP 409. code is the platform’s error string. |
rate_limited |
retryAfterMs? |
HTTP 429 after retries are exhausted. |
outcome_unknown |
method, url, status?, body?, cause? |
A request that is not repeatable (a plain POST) got a 502, 503 or 504, or failed or timed out after it was sent. The SDK did not send it again. See Retries. |
Status mapping
Section titled “Status mapping”mapHttpStatusToError(status, body, message?) is exported and does the mapping. The message is the
body’s message, else its error, else HTTP <status>.
| Status | Result |
|---|---|
| 401 | token_expired |
| 403 | forbidden |
| 404 | not_found |
| 409 | conflict (with the body’s error as code) |
| 422 | validation (with the body’s errors) |
| 429 | rate_limited (with retryAfter seconds from the body, converted to ms) |
| anything else, including 400 and 5xx | http_error with status and the raw body |
Notice that 400 is an http_error, not validation. The platform answers most request
validation failures with 400, so read error.body for the platform’s error code. For example, setting a
masked secret returns http_error with status: 400 and body.error === 'SECRET_VALUE_MASKED', and
revealing a plain property returns http_error with body.error === 'NOT_A_SECRET'.
Retries
Section titled “Retries”A request is repeatable when its method is GET, HEAD, OPTIONS, PUT or DELETE, or when it is
marked repeatable (the declarative syncs). Before an error reaches you, up to retryAttempts retries
are made with exponential backoff, and a first 401 triggers one token refresh:
408and429, and a connection that could not be made, are retried for every request.502,503and504, and a connection failure or timeout after the request was sent, are retried for a repeatable request. For any other request they returnoutcome_unknownat once, without a second attempt: the platform may have applied the request, so sending it again could apply it twice or, forprovisionServiceAccount, be refused with the first call’s one-time secrets lost. Read the state first (for a provisioning,applications().getServiceAccount(id)), then decide.- Everything else, including
500, is returned immediately.
Partial failure from sync
Section titled “Partial failure from sync”client.definitions().sync(), syncAll() and syncGrouped() can resolve Err after having done
useful work. The error is a PartialFailureError<T>:
type PartialFailureError<T> = { type: 'partial_failure'; message: string; partial: T };partial is the whole SyncResult (a SyncResult[] for syncAll, a Record<string, SyncResult>
for syncGrouped), so what succeeded is not lost. It is deliberately not part of SdkError;
narrow with isPartialFailureError(error) or check error.type === 'partial_failure'.
partialFailureError(message, partial) builds one. See Sync.
Use-case errors
Section titled “Use-case errors”The usecase envelope returns usecase.Result<T>, not a ResultAsync. Its failure carries a
UseCaseError, a value with type, code, message and details:
Kind (type) |
Factory | HTTP status via UseCaseError.httpStatus |
|---|---|---|
validation |
UseCaseError.validation(code, message, details?) |
400 |
authorization |
UseCaseError.authorization(...) |
403 |
not_found |
UseCaseError.notFound(...) |
404 |
business_rule |
UseCaseError.businessRule(...) |
409 |
concurrency |
UseCaseError.concurrency(...) |
409 |
infrastructure |
UseCaseError.infrastructure(...) |
500 |
UseCaseError.isUseCaseError(value) is a type guard. The Effect flavour has the same six kinds as
tagged classes; see Effect.
Exceptions that are thrown
Section titled “Exceptions that are thrown”These are programming or configuration errors, caught with try and catch:
| Thrown | When |
|---|---|
Error from CreateEventDto.create or CreateDispatchJobDto.create |
The type or code is not a four-segment application:subdomain:aggregate:action string. |
Error from OutboxManager |
The clientId is empty. |
PushError (code) |
A push is refused when built or written: TOPIC_INVALID, TYPE_INVALID, TYPE_RESERVED, DATA_INVALID, DATA_NOT_OBJECT, DATA_TOO_LARGE, PUSH_ID_INVALID, CLIENT_INVALID. Inside Plan.andPush it becomes a validation UseCaseError instead. |
TicketError |
A ticket or ticket key cannot be valid (bad key, topic outside the application, TTL out of range, too many keys or topics). |
WebhookSignatureError (code) |
verifyDeliverySignature failed; see Client for the codes. |
FieldError (reason) |
A field credential was refused; see Field. |
FieldVerifierUnavailableError |
Discovery or key fetch failed. Answer 503, not 401. |
CacheError |
A cache TTL is not positive, or a backend or serialisation error. |
Error from defineApplicationFromEnv |
FLOWCATALYST_APP_CODE is unset. |
Handling advice
Section titled “Handling advice”- Treat
token_expiredon a long-lived service as a signal to check clocks and credentials; the client already refreshed once. - Do not retry
conflictorhttp_errorwith status 400; they will fail the same way. - Log
error.typeanderror.message, never a request body that may hold a secret.