ruLog in to Senler

SDK Errors

Handle errors around SDK client calls.

Errors

The SDK exports three main error classes:

  • ResponseError means the API returned an unsuccessful HTTP status; the original Response is available as error.response;
  • FetchError means the request did not receive a response, for example because of a network error;
  • RequiredError means a required method parameter was omitted.

Handle the Error

import {
  FetchError,
  RequiredError,
  ResponseError,
} from "@senlerio/api";

try {
  await client.projects.getMe();
} catch (error) {
  if (error instanceof ResponseError) {
    const details = await error.response.clone().json().catch(() => null);
    console.error(error.response.status, details);
  } else if (error instanceof RequiredError) {
    console.error("Missing parameter:", error.field);
  } else if (error instanceof FetchError) {
    console.error("Network error:", error.cause);
  } else {
    throw error;
  }
}

For a 401 response, check whether the token is current. For 403, check token permissions and user permissions. For an entity error, verify projectId, the resource ID, and the token scope.

For a server-side OAuth integration, you can enable automatic token refresh.