Skip to main content
Version: v3.0.0 (current)

MagmaStreamError

The error MagmaStream throws, and emits as ManagerError or NodeError when it cannot throw to the bot. code names the case, number is its numeric ID and context holds the values involved.

export class MagmaStreamError<T = unknown> extends Error {}

Constructor​

new MagmaStreamError<T>({ code, message, cause, context }: MagmaStreamErrorOptions<T>)

Creates an error with its code, the number of that code and an optional context. The message defaults to the code. See MagmaStreamErrorOptions.

Properties​

PropertyTypeDescription
namestringAlways "MagmaStreamError".
codeMagmaStreamErrorCodeThe code of the error, such as PLAYER_QUEUE_EMPTY (read-only).
numbernumberThe numeric ID of the code, from MagmaStreamErrorNumbers (read-only).
contextT | undefinedThe values involved, such as the option or the guild, when the error gives them (read-only). A REST_REQUEST_FAILED thrown for an error response of the node has its HTTP status in context.status.

The standard Error properties (message, cause, stack) are set as usual.

Methods​

is()​

static is(err: unknown, code?: MagmaStreamErrorCode): err is MagmaStreamError;

Tells whether a caught value is a MagmaStreamError, with the given code when one is passed, and narrows its type.

import { MagmaStreamError, MagmaStreamErrorCode } from "magmastream";

try {
await player.setVolume(volume);
} catch (err) {
if (MagmaStreamError.is(err, MagmaStreamErrorCode.PLAYER_INVALID_VOLUME)) return reply("Volume from 0 to 1000.");
throw err;
}

MagmaStreamError.from() and MagmaStreamError.messageOf() are internal and not part of the published types.