# 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);
  }
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://developer.firmhouse.com/sdks/firmhouse-sdk/handling-errors.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
