InsionInsion
TypeScript

Errors and raw responses

Handle API failures and inspect response metadata

The client rejects a request when Insion returns a non-success status code or the request cannot reach the API. Catch InsionApiError to inspect the HTTP status and response body.

import { InsionApiError } from "insion";

try {
  await client.moderateARecord({
    clientId: "post-123",
    name: "A post",
    entity: "post",
    content: "Hello world",
  });
} catch (error) {
  if (error instanceof InsionApiError) {
    console.error(error.statusCode, error.body);
  }
  throw error;
}

For headers and the unparsed response, call .withRawResponse() on the promise returned by an API method. It resolves to a wrapper containing data and rawResponse.

const response = await client.listRecords({ limit: 20 }).withRawResponse();
console.log(response.data);
console.log(response.rawResponse.status);
console.log(response.rawResponse.headers);