> ## Documentation Index
> Fetch the complete documentation index at: https://docs.trychannel3.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Error Handling

When the library cannot connect to the API, or the API returns a non-success status code (4xx or 5xx), an error is thrown.

<CodeGroup>
  ```typescript TypeScript theme={null}
  import Channel3 from "@channel3/sdk";

  const client = new Channel3();

  async function main() {
    try {
      await client.products.search({ query: "running shoes" });
    } catch (err) {
      if (err instanceof Channel3.APIError) {
        console.log(err.status); // e.g. 400
        console.log(err.name); // e.g. BadRequestError
        console.log(err.headers); // { server: 'nginx', ... }
      } else {
        throw err;
      }
    }
  }

  main();
  ```

  ```python Python theme={null}
  from channel3_sdk import Channel3
  from channel3_sdk.errors import APIError

  client = Channel3()

  def main():
      try:
          client.products.search(query="running shoes")
      except APIError as e:
          print(f"Status code: {e.status_code}")
          print(f"Error name: {e.request.body.get('error', {}).get('type')}")
          print(f"Headers: {e.headers}")

  if __name__ == "__main__":
      main()
  ```
</CodeGroup>

<Note>Error types are exposed via each SDK's error module.</Note>
