Triggering from your app
Errors
Every error the client throws is a BokJoyError, with a subclass that says what went wrong. Catch the ones your code can act on.
Error classes#
Every client error is a BokJoyError. It has status, the HTTP status when the control plane answered (otherwise null), and body, the answer's body. Messages carry the control plane's reason and never the API key.
| Error | HTTP | When |
|---|---|---|
AuthenticationError | 401 | No key is configured, or the key is wrong or revoked. |
PermissionDeniedError | 403 | The key may not use this route. Environment keys reach only tasks, runs and schedules. |
NotFoundError | 404 | No such run, schedule or environment, or a run or schedule in another environment than the key's. |
ConflictError | 409 | An idempotency key reused with a different request, or an archived environment, or one with no current deployment, or an update or delete of a declared schedule. |
ValidationError | 400, 413, 422 | The request is invalid: a task the deployment does not have, a bad or refused option, a payload over 3 MiB, a request body over its limit. |
CapacityError | 400 | The run asks for more CPU or memory than its environment allows for its placement, so it could never start. A kind of ValidationError. |
ApiConnectionError | The control plane could not be reached, did not answer in time, or redirected, after every retry. | |
RunFailedError | A run you waited for failed or was cancelled. The run is on error.run. | |
WaitTimeoutError | A wait passed its timeout. error.run is the run's last state, or null. See Wait for a run. |
A 405 means the control plane does not offer the route, usually because it is older than your SDK. It throws a plain BokJoyError that says so.
Catch errors#
All the classes are exported from the package root:
import { tasks, ConflictError, ValidationError, ApiConnectionError,} from '@bokjoy/sdk'; try { await tasks.trigger('email.send', payload, { idempotencyKey: `order-${orderId}:receipt`, });} catch (error) { if (error instanceof ConflictError) { // This key already started a run with another payload. } else if (error instanceof ValidationError) { console.error('refused:', error.message); } else if (error instanceof ApiConnectionError) { // Unreachable after retries: try again later with the same key. } else { throw error; }}from bokjoy import ( ApiConnectionError, ConflictError, ValidationError, tasks,) try: tasks.trigger( "email.send", payload, idempotency_key=f"order-{order_id}:receipt", )except ConflictError: pass # This key already started a run with another payload.except ValidationError as error: print("refused:", error)except ApiConnectionError: pass # Unreachable after retries: try again later with the same key.In Python, the classes are the same objects under bokjoy and its older name, so an except clause catches them whichever name raised them.
What to retry#
| Error | Retry? |
|---|---|
ApiConnectionError | Yes, with the same idempotency key. The client already retried. |
RunFailedError | Read error.run.error first. Retrying with the same key returns the same failed run, so use a new key. A run started from @bokjoy/sdk/trigger with a key releases it when it fails, as on Trigger.dev, so the same key starts a new run there. |
WaitTimeoutError | Wait again with runs.poll. The run is still going. |
ConflictError, ValidationError, CapacityError | No. Fix the request. |
AuthenticationError, PermissionDeniedError | No. Fix the key. |
Errors inside a run#
A run's own failure is not a client error. When a task throws, the attempt fails and the run retries after a growing wait until max_attempts, then ends failed with the last error in run.error. A task that throws AbortTaskRunError, or whose handler runs past its timeout_ms, ends failed at once, with no retry. Retries and timeouts covers what happens inside the run.