We are currently working on a new version of the documentation.

Error Handling

Handle client errors with callbacks, reactive state, and throwOnError control.

Every vs3 client operation can fail — from local validation to network errors to server rejections. The client provides three complementary strategies for handling errors.

Error State

By default, errors are stored in the hook/composable state and never thrown:

const { state, upload } = useUpload();

await upload(file, metadata);

if (state.status === "error") {
  console.log(state.error?.code);    // e.g. "FILE_TOO_LARGE"
  console.log(state.error?.message); // Human-readable description
}

This works well for rendering error UI without try/catch blocks.

Error Callbacks

Use the onError callback for side effects like logging or analytics:

const { upload } = useUpload({
  onError: (error) => {
    reportToAnalytics(error.code, error.message);
  },
});

Callbacks run regardless of the throwOnError setting. They fire after the error is stored in state.

throwOnError

When throwOnError is true, the hook/composable rethrows the error after storing it in state and invoking callbacks:

const { upload } = useUpload({ throwOnError: true });

try {
  await upload(file, metadata);
} catch (error) {
  // error is a StorageError
}

Priority

throwOnError can be set at two levels. The hook/composable option takes priority:

  1. Hook/composable optionuseUpload({ throwOnError: true })
  2. Client optioncreateStorageClient({ throwOnError: true })
  3. Defaultfalse

Set it on the client to apply globally, then override per-hook where needed.

StorageError

All errors are instances of StorageError with structured fields:

FieldTypeDescription
codeStorageErrorCodeMachine-readable error code
messagestringHuman-readable description
origin"client" | "server"Whether the error was raised on the client or server
detailsunknownAdditional context (file info, validation details)
httpStatusnumberHTTP status code (server errors)
recoverySuggestionstringSuggested fix for the error

Client vs Server Errors

  • Client errors (origin: "client") are raised before any network request — validation failures, network errors, or invalid responses.
  • Server errors (origin: "server") are returned by the server — auth failures, metadata validation, storage errors.

Common Error Codes

CodeOriginWhen
FILE_TOO_LARGEclientFile exceeds maxFileSize
FILE_TYPE_NOT_ALLOWEDclientFile type not in allowedFileTypes
INVALID_FILENAMEclientFile name contains invalid characters
NETWORK_ERRORclientNetwork request failed
UPLOAD_FAILEDclientXHR upload returned non-success status
METADATA_VALIDATION_ERRORserverMetadata failed schema validation
UNAUTHORIZEDserverMissing or invalid auth credentials
FORBIDDENserverAuth valid but insufficient permissions

For the full list, see Error Model.

Next Steps