Skip to main content

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.
ParameterTypeDescription
messagestringError message describing the failure.

Properties

PropertyTypeDescription
messagestringThe error message inherited from the base Error class.
namestringThe name identifier for the error class.
stackstring(Optional) A string representing the location in the code at which the error was thrown.
stackTraceLimitnumberStatic. Specifies the number of stack frames collected by a stack trace. Default is 10.

Methods

captureStackTrace()

Static
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()

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.
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);
  }
}
This class is defined in src/errors/memmachine-api-error.ts.