Skip to main content

Main Error Type

The TypeScript SDK throws one typed error class for API failures:
import { BrewApiError } from '@brew.new/sdk'
BrewApiError gives you:
  • status
  • code
  • type
  • message
  • param
  • suggestion
  • docs
  • requestId
  • retryAfter

Typical Catch Pattern

import { BrewApiError, createBrewClient } from '@brew.new/sdk'

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

try {
  await brew.contacts.getByEmail({ email: '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.

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.
try {
  await brew.contacts.list()
} 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:

Search Documentation

Type in the “Ask any question” search bar at the top left to instantly find relevant documentation pages.

ChatGPT/Claude Integration

Click “Open in ChatGPT” at the top right of any page to analyze documentation with ChatGPT or Claude for deeper insights.