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

# MemMachineAPIError

> Custom error class for handling MemMachine SDK and API failures.

## Overview

The `MemMachineAPIError` class is a custom error implementation used to represent failures returned by MemMachine client methods. It serves as the primary mechanism for catching and identifying SDK-specific issues.

### Hierarchy

* **Error**
  * **MemMachineAPIError**

***

## Constructor

### `new MemMachineAPIError(message)`

Initializes a new instance of the error with a specific descriptive message.

| Parameter | Type     | Description                           |
| :-------- | :------- | :------------------------------------ |
| `message` | `string` | Error message describing the failure. |

***

## Properties

| Property          | Type     | Description                                                                                   |
| :---------------- | :------- | :-------------------------------------------------------------------------------------------- |
| `message`         | `string` | The error message inherited from the base `Error` class.                                      |
| `name`            | `string` | The name identifier for the error class.                                                      |
| `stack`           | `string` | (Optional) A string representing the location in the code at which the error was thrown.      |
| `stackTraceLimit` | `number` | **Static.** Specifies the number of stack frames collected by a stack trace. Default is `10`. |

***

## Methods

### `captureStackTrace()`

```typescript Static theme={null}
captureStackTrace(targetObject: object, constructorOpt?: Function): void
```

Creates a `.stack` property on `targetObject`, which when accessed returns a string representing the location in the code at which the method was called. This is useful for hiding implementation details of error generation from the user.

### `prepareStackTrace()`

```typescript theme={null}
prepareStackTrace(err: Error, stackTraces: CallSite[]): any
```

A static hook used to customize the formatting of stack traces.

***

## Usage Example

Integrate `MemMachineAPIError` into your error handling logic to differentiate between API-specific failures and general runtime errors.

```typescript theme={null}
import { MemMachineAPIError } from '@memmachine/client';

try {
  // SDK Call
} catch (error) {
  if (error instanceof MemMachineAPIError) {
    // Handle specific MemMachine failures
    console.error(`API Error: ${error.message}`);
  } else {
    // Handle standard JavaScript or network errors
    console.error('System Error:', error);
  }
}
```

<Note> This class is defined in `src/errors/memmachine-api-error.ts`. </Note>
