Skip to content

SDK Errors

The SDK throws SdkError when a request fails (network, HTTP, or GraphQL errors). It extends Error and adds a code and optional details.

Error shape

import { SdkError, isSdkError } from '@mindsize/simple-feature-requests-sdk';

try {
  await client.teams.get('id');
} catch (err) {
  if (isSdkError(err)) {
    console.log(err.name);   // "SdkError"
    console.log(err.message); // Human-readable message
    console.log(err.code);    // See codes below
    console.log(err.details?.statusCode);
    console.log(err.details?.graphqlErrors);
  }
}

Error codes

Code Meaning Typical HTTP
UNAUTHORIZED Missing or invalid auth 401
FORBIDDEN Not allowed to access or modify resource 403
NOT_FOUND Resource not found 404
VALIDATION Invalid input (e.g. validation failed) 400
BAD_REQUEST Other client error 4xx
SERVER Server or upstream error 5xx
NETWORK Fetch failed (e.g. connection refused)
UNKNOWN Unexpected or unclassified

Details

  • details.statusCode: HTTP status when the response was received.
  • details.graphqlErrors: When the API returns a GraphQL errors array, it is attached here (each item has message and optional extensions).

For the full list of API error messages and when they occur, see API Errors.