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

# TypeScript Error Handling

> Handle BrewApiError and transport failures in the Brew TypeScript SDK

## Main Error Type

The TypeScript SDK throws one typed error class for API failures:

```ts theme={null}
import { BrewApiError } from '@brew.new/sdk'
```

`BrewApiError` gives you:

* `status`
* `code`
* `type`
* `message`
* `param`
* `suggestion`
* `docs`
* `requestId`
* `retryAfter`

## Typical Catch Pattern

```ts theme={null}
import { BrewApiError, createBrewClient } from '@brew.new/sdk'

const brew = createBrewClient({
  apiKey: process.env.BREW_API_KEY!,
})

try {
  await brew.contacts.search({
    filters: [{ field: 'email', operator: 'equals', value: 'missing@example.com' }],
  })
} catch (error) {
  if (error instanceof BrewApiError) {
    console.error(error.code)
    console.error(error.message)
    console.error(error.requestId)
  }
  throw error
}
```

## What To Branch On

* Use `type` for broad categories like `not_found` or `rate_limit`.
* Use `code` for specific product cases like `CONTACT_NOT_FOUND`.

## Common error codes

| Code                       | Retry? | Guidance                                                               |
| -------------------------- | ------ | ---------------------------------------------------------------------- |
| `RATE_LIMITED`             | Yes    | Honor the `Retry-After` header verbatim.                               |
| `INTERNAL_ERROR`           | Once   | Log `requestId` and include it when contacting support.                |
| `IDEMPOTENCY_CONFLICT`     | No     | Inspect the original request; same key was used with a different body. |
| `INVALID_REQUEST`          | No     | Fix the request body — same payload will fail identically.             |
| `INSUFFICIENT_PERMISSIONS` | No     | Check the key's scopes in the dashboard.                               |
| `INVALID_API_KEY`          | No     | Check the key value; rotate if exposed.                                |

See the [full error code catalog](/api-reference/api/api-introduction) in the API introduction.

## API Errors vs Transport Errors

There are two buckets:

### API error

The server answered with a non-2xx response. You get `BrewApiError`.

### Transport error

The network failed and retries were exhausted. You get a normal `Error`.

```ts theme={null}
try {
  await brew.contacts.search({ search: 'jane' })
} catch (error) {
  if (error instanceof BrewApiError) {
    console.error('API error', error.code)
  } else if (error instanceof Error) {
    console.error('Transport error', error.message)
  }
  throw error
}
```

## Helpful Notes

* Log `requestId` when asking Brew support for help.
* Trust the SDK retry behavior first before adding your own retry loop.
* For `POST` requests, let the SDK keep idempotency on by default.

## Need Help?

Our team is ready to support you at every step of your journey with Brew. Choose the option that works best for you:

<Tabs>
  <Tab title="Self-Service Tools">
    <CardGroup cols="2">
      <Card title="Search Documentation" icon="magnifying-glass" color="#c44925">
        Type in the "Ask any question" search bar at the top left to instantly find relevant documentation pages.
      </Card>

      <Card title="ChatGPT/Claude Integration" icon="robot" color="#c44925">
        Click "Open in ChatGPT" at the top right of any page to analyze documentation with ChatGPT or Claude for deeper insights.
      </Card>
    </CardGroup>
  </Tab>

  <Tab title="Talk to Our Team">
    <CardGroup cols="2">
      <Card title="Schedule a Call" icon="calendar" color="#c44925" href="https://calendar.google.com/calendar/u/0/appointments/schedules/AcZssZ1iYoRUG1J792XQpbuQLjSRRDupr7MwraFK-HQRCtTYdBmrQi8nZu2qXfzKQigb8gbKJK3KN3-R">
        Book time with our founders for personalized guidance on strategy, best practices, or complex implementation questions.
      </Card>

      <Card title="Call Us Directly" icon="phone" color="#c44925">
        Need immediate assistance? Reach us at **+1-(332)-203-2145** for urgent issues or time-sensitive questions.
      </Card>

      <Card title="Slack Channel" icon="slack" color="#c44925">
        Our preferred support channel. You'll receive an invite after signup for direct founder support and fast responses.
      </Card>

      <Card title="Email Support" icon="envelope" color="#c44925" href="mailto:support@brew.new">
        Contact us at **[support@brew.new](mailto:support@brew.new)** for detailed inquiries or if you prefer not to use Slack.
      </Card>
    </CardGroup>
  </Tab>
</Tabs>
