Skip to main content
All HTTP errors from the SDK are instances of KosliError or one of its subclasses. Network-level failures throw one of the client error classes listed below.

KosliError

KosliError is the base class for any non-2xx HTTP response. It exposes:
PropertyTypeDescription
messagestringError message
statusCodenumberHTTP status code (e.g. 404, 403)
headersHeadersResponse headers
bodystringRaw response body (may be empty)
rawResponseResponseThe full HTTP response object
data$variesStructured error data for specific error types (see below)

HTTP error classes

These named subclasses cover the most common API errors:
ClassStatusDescription
BadRequestError400Invalid request
UnauthorizedError401Permission denied or not authenticated
NotFoundError404Resource not found
RateLimitedError429Rate limit exceeded
import { Kosli } from "@kosli/sdk";
import * as errors from "@kosli/sdk/models/errors";

const kosli = new Kosli({
  httpBearer: process.env["KOSLI_API_KEY"] ?? "",
});

try {
  const trail = await kosli.trails.get({}, {
    org: "my-org",
    flowName: "my-flow",
    trailName: "my-trail",
  });
} catch (error) {
  if (error instanceof errors.NotFoundError) {
    console.error("Trail not found");
  } else if (error instanceof errors.UnauthorizedError) {
    console.error("Access denied:", error.data$.message);
  } else if (error instanceof errors.RateLimitedError) {
    console.error("Rate limit hit - back off and retry");
  } else if (error instanceof errors.KosliError) {
    console.error(`HTTP ${error.statusCode}: ${error.message}`);
  }
}

Network errors

These errors are thrown when the request cannot be completed at the transport level:
ClassDescription
ConnectionErrorThe HTTP client could not reach the server
RequestTimeoutErrorThe request was aborted by an AbortSignal timeout
RequestAbortedErrorThe request was cancelled by the caller
InvalidRequestErrorThe request could not be constructed (invalid input)
UnexpectedClientErrorAn unrecognised error occurred in the HTTP client
Network errors do not have a statusCode - handle them separately from KosliError:
import * as errors from "@kosli/sdk/models/errors";

try {
  const result = await kosli.trails.list({}, { org: "my-org", flowName: "my-flow" });
} catch (error) {
  if (error instanceof errors.ConnectionError) {
    console.error("Could not connect to Kosli - check your network");
  } else if (error instanceof errors.RequestTimeoutError) {
    console.error("Request timed out");
  } else if (error instanceof errors.KosliError) {
    console.error(`API error ${error.statusCode}: ${error.message}`);
  } else {
    throw error;
  }
}

Other errors

A small number of operations can throw additional error types for specific conditions:
ClassStatusDescription
ConflictResponseModelError409Conflict (e.g. resource already exists)
RequestEntityTooLargeResponseModelError413Request body too large
ResponseValidationError-Response from server did not match the expected schema; inspect error.rawValue or call error.pretty()
Check the method’s documentation to see which errors apply to a specific operation.
Last modified on June 22, 2026