Raster

Errors

Failed calls reject with a RasterApiError. Branch on its code and show the user toUserMessage(error).

Every failed call, sign-in included, rejects with a RasterApiError. React hooks report the same error as error, or as { status: 'error', error } in sign-in, upload, and promote states. If your credential store fails to save, the call rejects with the store's error instead.

import { RasterApiError, toUserMessage } from '@raster-app/sdk'

try {
  await raster.assets.list({ organizationId: 'acme', libraryId: 'lib-1' })
} catch (error) {
  if (error instanceof RasterApiError && error.code === 'NOT_SIGNED_IN') {
    // Show your sign-in screen.
  } else {
    alert(toUserMessage(error))
  }
}

RasterApiError

RasterApiError extends Error, with name set to 'RasterApiError'.

PropertyDescription
codeThe code to branch on.
statusThe HTTP status, or 0 when there is none.
messageA description of the failure.

API errors keep the API's code, message, and status (see Error codes). A failed sign-in carries the OAuth error as its code.

Codes the SDK raises

CodeStatusWhen
ABORTED0The call's signal was aborted, or a sign-in was cancelled.
TIMEOUT0An AbortSignal.timeout() signal on a library, asset, or search method ran out.
NETWORK_ERROR0The request couldn't reach Raster, for example when offline or blocked by a network policy.
NOT_SIGNED_IN401No credential is stored. No request was sent.
SESSION_EXPIRED401The sign-in ended, for example because the user revoked it. The client signs out.
API_KEY_REQUIRED400auth.connect got an empty API key.
ORGANIZATION_MISMATCH403A sign-in bound to an organizationId was granted another organization or the whole account.
access_deniedThe response'sThe user denied access.
expired_tokenThe response'sThe sign-in code expired before approval.
HTTP_ERRORThe response'sA request failed with no error in the body.
MALFORMED_RESPONSEThe response'sA response had an unexpected shape.
UNKNOWN0, or the response'sA non-RasterApiError passed to toRasterApiError, or an API error with no code.

toUserMessage(error)

toUserMessage(error) returns a sentence to show the user. It accepts any thrown value.

It has its own wording for UNAUTHENTICATED, INVALID_API_KEY, RESOURCE_NOT_FOUND, NOT_FOUND, API_KEY_NOT_AUTHORIZED_FOR_LIBRARY, NETWORK_ERROR, TIMEOUT, NOT_SIGNED_IN, SESSION_EXPIRED, access_denied, and expired_token. Other codes return the error's message.

Helpers

FunctionReturns
isAbortError(error)true for ABORTED, a cancel your app asked for. See Cancelling a call.
toRasterApiError(caught)Any thrown value as a RasterApiError, with UNKNOWN for non-RasterApiError values.

On this page