Skip to Content

Errors

The errors @osdk/client throws, the fields of PalantirApiError and ActionValidationError, Result-returning methods, retries, and patterns for handling them.

Every @osdk/client method that sends a request rejects on failure. This page lists what it rejects with, which fields to branch on, and the methods that return a result instead of throwing.

Error types

ErrorImportThrown when
PalantirApiError@osdk/clientFoundry returned an error response, the request never got a response (DNS, TLS, CORS, or connection failure), or the error body was not JSON. In the last two cases errorCode and errorName are undefined, and the original error is on error.cause.
ActionValidationError@osdk/clientapplyAction ran the action's validation and it failed.
ErrorBuilt inThe client rejected your input before sending anything. See Errors before a request.

An error thrown by your token provider reaches you as a plain Error whose message starts with Captured stack trace for error:. The original error is on error.cause.

PalantirApiError

FieldTypeDescription
messagestringThe server's message, or Failed to fetch <status> <statusText>.
errorCodestring | undefinedThe category, such as PERMISSION_DENIED, NOT_FOUND, INVALID_ARGUMENT, CONFLICT, or TIMEOUT.
errorNamestring | undefinedThe specific error, such as ObjectTypeNotFound or ActionNotFound.
errorDescriptionstring | undefinedA longer description.
statusCodenumber | undefinedThe HTTP status. undefined when no response arrived.
errorInstanceIdstring | undefinedAn ID for this occurrence. Log it, and include it when you report a problem to your Foundry administrator.
parametersunknownError-specific details, such as the API name that was not found.

When the request never got a response, statusCode is undefined. The low-level error is on error.cause, and its originalError holds the TypeError from the failed fetch.

When no object matches, fetchOne and $link.<link>.fetchOne reject with a PalantirApiError that carries only a message, Expected a single result but got 0 instead, and no statusCode, errorCode, or errorName.

Branch on statusCode and errorCode, which are stable. Use errorName for a specific case. Do not parse message.

src/describeError.ts
import { PalantirApiError } from "@osdk/client";

export function describeError(error: unknown): string {
  if (!(error instanceof PalantirApiError)) {
    return error instanceof Error ? error.message : String(error);
  }
  if (error.statusCode == null && error.errorCode == null) {
    return "Could not reach Foundry. Check the network and the Foundry URL.";
  }
  if (error.statusCode === 401) {
    return "The token is missing or expired.";
  }
  if (error.errorCode === "PERMISSION_DENIED" || error.statusCode === 403) {
    return "You do not have access to this data.";
  }
  if (error.errorCode === "NOT_FOUND") {
    return `Not found: ${error.errorName ?? error.message}`;
  }
  return `${error.message} (error instance ${error.errorInstanceId ?? "unknown"})`;
}

A NOT_FOUND error can also mean that the user cannot see a resource that exists.

ActionValidationError

applyAction throws ActionValidationError when the server ran the action's submission criteria and parameter constraints and they failed. It is not a PalantirApiError. Its validation field has result, submissionCriteria, and parameters. See Actions for the shape and a message helper.

batchApplyAction does not throw it. A batch that fails validation rejects with a PalantirApiError.

Methods that return a result

Three methods resolve to a Result instead of rejecting:

MethodOn
fetchOneWithErrors(primaryKey, options?)Object type sets
fetchPageWithErrors(options?)Every object set
$link.<link>.fetchOneWithErrors(options?)Single links

A Result is { value } on success or { error } on failure, where error is an Error. Narrow it with isOk from @osdk/client:

src/optionalLead.ts
import { Employee } from "@my-app/sdk";
import { isOk } from "@osdk/client";
import { client } from "./client";

const result = await client(Employee).fetchOneWithErrors(12345, { $select: ["fullName"] });

if (isOk(result)) {
  console.log(result.value.fullName);
} else {
  console.warn("Employee not available:", result.error.message);
}

error is the same error the throwing variant would have thrown, so the narrowing above still applies.

Retries

The client retries a request that fails with 429 Too Many Requests or 503 Service Unavailable, up to three times. The delays grow exponentially from about one second, with random jitter. Other errors, including network failures, are not retried. Your code sees the error only after the last attempt.

Errors before a request

These throw a plain Error before any request is sent:

ErrorCause
Invalid ontology RIDcreateClient got an Ontology RID string that does not start with ri.. If you pass a Promise, the check runs when it resolves and surfaces as an unhandled rejection instead.
baseUrl cannot be emptycreateClient got an empty base URL. A malformed URL throws a TypeError from new URL.
Cannot filter on property "<name>" with an undefined or null valueA where clause had a null or undefined value. See Filter objects.
A WhereClause Filter with multiple clauses/fields is not allowedOne property in a where clause had more than one operator.
Object does not implement interface '<name>'$as was called with an interface the object type does not implement. See Interfaces.

Messages from where validation are prefixed Invariant failed: , and production builds (NODE_ENV=production) drop the detail and throw only Invariant failed.

executeFunction on a function with a union return type runs the function, then throws Union return types are not yet supported while reading the result. See Functions.

Patterns

  • Await every call inside try/catch, or attach .catch. A rejected promise that nothing handles crashes a Node.js process and logs an unhandled rejection in the browser.
  • Catch ActionValidationError before PalantirApiError, and show the validation messages to the user. Other action errors usually need a retry or an administrator.
  • For loads where a missing object is expected, use the WithErrors variants instead of catching.
  • In long jobs, log errorInstanceId and errorName with each failure, and keep going instead of stopping at the first error.

For errors in @osdk/react hooks, see Loading and errors.

On this page