---
title: "Reference: Error Handling | Client SDK"
description: Learn about the built-in retry mechanism and error handling capabilities in the Mastra client-js SDK.
packages:
  - "@mastra/client-js"
---

# Error Handling

The Mastra Client SDK includes built-in retry mechanism and error handling capabilities.

## Error Handling

All API methods can throw errors that you can catch and handle:

```typescript
try {
  const agent = mastraClient.getAgent("agent-id");
  const response = await agent.generate({
    messages: [{ role: "user", content: "Hello" }],
  });
} catch (error) {
  console.error("An error occurred:", error.message);
}
```
