> For the complete documentation index, see [llms.txt](https://developer.firmhouse.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.firmhouse.com/sdks/firmhouse-sdk/handling-errors.md).

# Handling Errors

When interacting with the Firmhouse API, you might encounter errors such as validation errors, not found errors, server errors etc. You can handle these errors by catching them and handling them accordingly.

## Not Found Error

```typescript
import { NotFoundError } from '@firmhouse/firmhouse-sdk';

try {
  const products = await client.products.fetch("invalid-product-id")
} catch (error) {
  if (error instanceof NotFoundError) {
   console.log("Product not found");
  }
}
```

## Validation Error

```typescript
import { ValidationError } from '@firmhouse/firmhouse-sdk';

try {
  const cart = await client.carts.updateAddressDetails("<cart-token>", { email: "invalid-email" });
} catch (error) {
 if (error instanceof ValidationError) {
   const { details } = error;
   const { email } = details;
   console.log(email); // "Email is not valid"
 }
}
```

## Server Error

```typescript
import { ServerError } from '@firmhouse/firmhouse-sdk';

try {
 const subscription = await client.subscriptions.get("invalid-subscription-token");
} catch (error) {
  if (error instanceof ServerError) {
    console.log(error.message);
  }
}
```
