Error Handling

Open in Claude

VimConnectError, every status the API answers with, and what is retried for you

A request the API answers with a non-2xx status throws a VimConnectError. Switch on statusCode: the API's routes do not set code today, so it is undefined.

import { VimConnectError, existingRecordIdOf } from '@vimconnect/backend-sdk';

try {
  await client.api.patient.create(input);
} catch (err) {
  const existing = existingRecordIdOf(err);
  if (existing) return client.api.patient.update({ id: existing, ...changes });
  if (err instanceof VimConnectError && err.statusCode === 403) {
    // this account did not grant your app this operation
  }
  throw err;
}

VimConnectError

FieldTypeWhat it holds
statusCodenumberThe HTTP status.
codestring | undefinedA machine-readable code, when the API sends one. The routes the Backend SDK calls do not, so switch on statusCode.
messagestringThe API's message. On the token mint it is the OAuth error (invalid_client, invalid_grant, …).
detailsRecord<string, unknown> | undefineddetails.operation names the call that failed, for example patient.create. A 409 also carries the existing record's id, read with existingRecordIdOf(err).
responseResponse | undefinedThe raw fetch response, for headers or anything else this table does not cover.

Error statuses

Token mint

The client mints a token on the first call and again before it expires. A mint is never retried.

StatusWhenHow to handle
400 invalid_grantThe account does not exist, or your app is not installed on itCheck accountId, and that the account accepted your app's invite
400 unauthorized_clientThe app is a point-of-care app, or has no live manifestUse a service app's credentials; publish its manifest
400 Validation ErrorclientId, clientSecret or accountId is missingPass all three to VimConnectBackendClient
401 invalid_clientThe clientId / clientSecret pair is wrongCheck the credentials; rotate the secret in the Console if it leaked

Operations

StatusWhenHow to handle
400The input is invalid: a required field is missing, a field is not declared for this operation, a filter is unknown, a protected value was sent in plaintext, or id is missing or not a UUIDFix the input; the message names the field. Do not retry
401The token expiredHandled for you: the client mints a new token and resends once. A second 401 reaches you; check that accountId is the account the token was minted for
403The account did not grant your app this operation, has not accepted Vim's terms, or the record is immutableAsk the account to grant the operation; do not retry
404The record does not exist in this account, or the operation is not offered to your appCheck the id. For an operation, check your SDK version against the API reference
409A create sent an identifier that another record already holdsRead the existing id with existingRecordIdOf(err) and update that record
422A lookup referred to a protected value this account does not holdCall lookup again with the patient's details
500The API failedRetry a read later. For a write, check whether it was applied before sending it again
502, 503, 504The API was briefly unavailableReads are retried for you (see retries in Configuration). Writes are never re-sent; check whether one was applied before sending it again

The API does not rate-limit these routes today. A 429 from anything in between is surfaced as is and not retried.

Errors that are not a VimConnectError

ErrorWhenHow to handle
VimConnectWriteRevealErrorA create or update was stored, but revealing its protected fields for the reply failed. It extends VimConnectError and carries written (always true) and vimEntityIdDo not send the write again. get the record by vimEntityId
Error: Request timed out after …msNo response within timeoutMs (default 30s). Reads are retried firstRetry a read later; check whether a write was applied before sending it again
The fetch error (for example TypeError)The network failed before any response. Reads are retried firstSame as a timeout
Your AbortSignal's reasonYou aborted the callNothing was answered; treat as cancelled
Error from the constructorVimConnectBackendClient was given invalid optionsFix the configuration
Error before a write is sentA create has no value for the record's identifier fieldAdd the identifier; nothing was sent

EHR errors

A client.ehr call fails with a VimConnectEhrError, a VimConnectError with a code. Its codes and what to do about each are on EHR access.

On this page