SpaceError
The error every SDK function fails with, its fields, and every code the SDK itself gives.
import { SpaceError, isSpaceError } from "digitospace"Every function in the SDK fails with a SpaceError. A function that returns a promise rejects with one. createSpace(), and the first use of space, throw one. To handle errors step by step, see Handle errors.
Fields
SpaceError extends Error, so it also has message, stack, and cause.
name"SpaceError"Always
SpaceError.codeSpaceErrorCodeWhat went wrong, as a stable code. Branch on it. It is one of the SDK’s codes, or a code from the service.
messagestringA sentence for a person, which may say what to do next. It may be reworded at any time, so never branch on it.
statusnumberThe HTTP status the service answered with, or
0when the failure happened in the SDK, such as a value checked before sending or a network failure.retryablebooleanWhether the same call could work if you try it again later. The SDK has already tried a call that is safe to repeat. See Retries.
requestIdstring | undefinedThe ID of the request, when the service answered. Quote it when you ask us for help.
issuesIssue[]For
validation_failed, every field that is wrong. Empty for every other code.resourcestring | undefinedFor
not_found, what is missing, when the service says, such asbucketorobject.causeunknownThe error underneath, when there is one, such as the runtime’s own network error.
Issue
Each issue names one field that is wrong.
fieldstringThe field, with dots for a field inside an object, such as
target.url.codestringWhy it is wrong, such as
requiredorinvalid.messagestringA sentence for a person, such as how the value should look.
isSpaceError()
isSpaceError(value: unknown): value is SpaceErrorWhether a value is a SpaceError. After it, TypeScript knows the value’s fields.
import { isSpaceError, space } from "digitospace"
try {
const file = await space.fs.stat("invoices/2026/0001.pdf")
console.log(file.size)
} catch (error) {
if (isSpaceError(error) && error.code === "not_found") console.log("No such file")
else throw error
}error instanceof SpaceError does the same.
Codes from the SDK
The SDK gives these codes itself, for failures before a call is sent, while it is under way, or after the answer arrives. Most have a status of 0, because no service answered.
Setting up
| Code | Status | Retryable | When |
|---|---|---|---|
validation_failed | 0 | no | An option, path, ID, message, or setting is not in the right form. Nothing was sent. issues names each field |
missing_api_key | 0 | no | The call needs a key and the client has none for its product. Set DIGITOSPACE_API_KEY, or pass apiKey or apiKeys |
missing_project | 0 | no | The call needs a project and the client has none. Set DIGITOSPACE_PROJECT, or pass project |
browser_not_allowed | 0 | no | The SDK is running in a web page. Call it from your server instead |
unsupported_runtime | 0 | no | The runtime has no fetch. Pass one in the fetch option |
Sending and answers
| Code | Status | Retryable | When |
|---|---|---|---|
timeout | 0 | yes | A try took longer than timeoutMs |
aborted | 0 | no | The call’s signal was aborted |
network_error | 0 | yes | The service could not be reached |
unexpected_response | 0, or the status | no | The answer was not JSON, or was not in the shape this version expects. Update digitospace |
Files
| Code | Status | Retryable | When |
|---|---|---|---|
file_too_large | 0 | no | space.fs.write was given more than 100,000,000 bytes. Nothing was sent |
upload_failed | The status | when 500 or higher | Storage did not accept the file’s bytes. The upload is cancelled |
download_failed | The status | when 500 or higher | Storage could not send the file. A file that is not there fails with not_found instead |
Chats and task streams
| Code | Status | Retryable | When |
|---|---|---|---|
stream_interrupted | 0 | yes | The stream ended before the answer finished |
stream_consumed | 0 | no | A task stream was read a second time. A task stream can be read once; a chat stream can be read again |
answer_invalid | 0, or the status | yes | The answer was not JSON, or did not match the schema given to chat(). issues names each field |
Verifying calls to your app
| Code | Status | Retryable | When |
|---|---|---|---|
invalid_signature | 401 | no | The call or delivery is not signed by us, is signed for someone else, or is too old. The message says which |
unexpected_job | 403 | no | A scheduler call came from a job not in jobs |
keys_unavailable | The status, or 0 | yes | The scheduler’s public keys could not be fetched to check a call |
Codes from the service
When the service refuses a call, its code passes through unchanged, with its status, requestId, issues, resource, and retryable. The message is the service’s own. So the codes in each product’s error reference are the codes you branch on:
- Storage error codes, such as
bucket_name_takenandstorage_quota_reached - AI error codes, such as
model_not_foundandunit_limit_reached - Scheduler error codes
Codes that every service shares, such as unauthenticated, forbidden, not_found, rate_limited, and unavailable, each have a page in Problems.
When an answer carries no code of its own, the SDK gives one from its status:
| Status | Code |
|---|---|
400 | invalid_request |
401 | unauthenticated |
403 | forbidden |
404 | not_found |
409 | conflict |
413 | payload_too_large |
422 | validation_failed |
429 | rate_limited |
500 | internal |
502, 503, or 504 | unavailable |
| Any other | unexpected_response |
Such an error is retryable when its status is 429, or 502 or higher.
An error the model sends partway through a chat stream ends the stream with that error’s code and a status of 0.
SpaceErrorCode
code has the type SpaceErrorCode: the most common codes, which your editor suggests, and any other string, because a service can add codes.
import type { SpaceErrorCode } from "digitospace"Last updated