Skip to content
Client
Server

Reference / @open-music-sdk/core / AppleMusicError

Class: AppleMusicError<Tag> ​

Defined in: packages/core/src/errors.ts:51

Every failure the SDK raises at runtime: what Apple answered, what the network did, or what a token provider could not do. _tag says which, as tErrorTag lists them, and narrows the type: isAppleMusicError(e, "RateLimited"). A caller's mistake in what it hands a function is never one of these; that is a TypeError, thrown before anything is sent.

Extends ​

  • Error

Type Parameters ​

Tag ​

Tag extends tErrorTag = tErrorTag

Constructors ​

Constructor ​

ts
new AppleMusicError<Tag>(
   tag, 
   message, 
   details?
): AppleMusicError<Tag>;

Defined in: packages/core/src/errors.ts:70

Parameters ​

tag ​

Tag

Which kind of failure this is.

message ​

string

What happened, in words that repeat no value: never a token, a key or what a caller passed.

details? ​

tErrorDetails = {}

What else is known: the status, Apple's errors, the validator's issues, a Retry-After, a cause.

Returns ​

AppleMusicError<Tag>

Overrides ​

ts
Error.constructor

Properties ​

_tag ​

ts
readonly _tag: Tag;

Defined in: packages/core/src/errors.ts:55

Which kind of failure this is.


cause? ​

ts
optional cause?: unknown;

Defined in: node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2022.error.d.ts:24

Inherited from ​

ts
Error.cause

errors ​

ts
readonly errors: readonly tError[] | undefined;

Defined in: packages/core/src/errors.ts:59

Apple's own errors, as its answer listed them; undefined when the body had none.


issues ​

ts
readonly issues: 
  | readonly tValidationIssue[]
  | undefined;

Defined in: packages/core/src/errors.ts:61

What the validator found wrong, on a ValidationError; undefined otherwise.


message ​

ts
message: string;

Defined in: node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es5.d.ts:1075

Inherited from ​

ts
Error.message

name ​

ts
readonly name: "AppleMusicError" = "AppleMusicError";

Defined in: packages/core/src/errors.ts:53

Always "AppleMusicError": with _tag, what makes a value one of these to instanceof and isAppleMusicError.

Overrides ​

ts
Error.name

retryAfterMs ​

ts
readonly retryAfterMs: number | undefined;

Defined in: packages/core/src/errors.ts:63

How long Apple's Retry-After header asked to wait, in milliseconds; undefined when there was no such header.


stack? ​

ts
optional stack?: string;

Defined in: node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es5.d.ts:1076

Inherited from ​

ts
Error.stack

status ​

ts
readonly status: number | undefined;

Defined in: packages/core/src/errors.ts:57

HTTP status of the answer that produced the error; undefined when there was none, as for a NetworkError.


stackTraceLimit ​

ts
static stackTraceLimit: number;

Defined in: node_modules/.pnpm/@types+node@24.19.1/node_modules/@types/node/globals.d.ts:68

The Error.stackTraceLimit property specifies the number of stack frames collected by a stack trace (whether generated by new Error().stack or Error.captureStackTrace(obj)).

The default value is 10 but may be set to any valid JavaScript number. Changes will affect any stack trace captured after the value has been changed.

If set to a non-number value, or set to a negative number, stack traces will not capture any frames.

Inherited from ​

ts
Error.stackTraceLimit

Methods ​

[hasInstance]() ​

ts
static [hasInstance](value): boolean;

Defined in: packages/core/src/errors.ts:87

instanceof goes by shape, not by constructor. Two copies of this package can be installed side by side, and an error made by one has to be recognised by the other's guard.

Parameters ​

value ​

unknown

What is on the left of instanceof.

Returns ​

boolean

Whether value is an Error named "AppleMusicError" with a string _tag, whichever copy of this class made it. Asked of a subclass, whether value was made by that subclass: the ordinary prototype check.


captureStackTrace() ​

ts
static captureStackTrace(targetObject, constructorOpt?): void;

Defined in: node_modules/.pnpm/@types+node@24.19.1/node_modules/@types/node/globals.d.ts:52

Creates a .stack property on targetObject, which when accessed returns a string representing the location in the code at which Error.captureStackTrace() was called.

js
const myObject = {};
Error.captureStackTrace(myObject);
myObject.stack;  // Similar to `new Error().stack`

The first line of the trace will be prefixed with ${myObject.name}: ${myObject.message}.

The optional constructorOpt argument accepts a function. If given, all frames above constructorOpt, including constructorOpt, will be omitted from the generated stack trace.

The constructorOpt argument is useful for hiding implementation details of error generation from the user. For instance:

js
function a() {
  b();
}

function b() {
  c();
}

function c() {
  // Create an error without stack trace to avoid calculating the stack trace twice.
  const { stackTraceLimit } = Error;
  Error.stackTraceLimit = 0;
  const error = new Error();
  Error.stackTraceLimit = stackTraceLimit;

  // Capture the stack trace above function b
  Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace
  throw error;
}

a();

Parameters ​

targetObject ​

object

constructorOpt? ​

Function

Returns ​

void

Inherited from ​

ts
Error.captureStackTrace

prepareStackTrace() ​

ts
static prepareStackTrace(err, stackTraces): any;

Defined in: node_modules/.pnpm/@types+node@24.19.1/node_modules/@types/node/globals.d.ts:56

Parameters ​

err ​

Error

stackTraces ​

CallSite[]

Returns ​

any

See ​

https://v8.dev/docs/stack-trace-api#customizing-stack-traces

Inherited from ​

ts
Error.prepareStackTrace

MIT licensed. Not affiliated with, endorsed by, or sponsored by Apple Inc. Apple Music and MusicKit are trademarks of Apple Inc.