Skip to main content

Class: BrowseError

Defined in: packages/media-session/src/browse.ts:79

Throw this (or reject with it) from any browse method to put the car's sign-in / upgrade screen on screen instead of an empty list.

override async getChildren(parentId: string) {
if (!this.session) {
throw new BrowseError('authenticationExpired', 'Sign in to browse your library.', {
label: 'Sign in',
url: 'myapp://signin',
})
}

}

What each platform actually draws

  • CarPlay draws all five codes as an alert with the message, plus the resolution button when one is given.
  • Android Auto is narrower, and honestly so: media3 replicates a library error into the platform playback state — the thing a legacy browser like Android Auto renders — for authenticationExpired and parentalControlRestricted only (MediaLibrarySessionImpl .isReplicationErrorCode, media3 1.11.0). The other three are returned faithfully as a LibraryResult error and are shown by Auto as an empty list. Use authenticationExpired for anything you want a button on.

Extends

  • Error

Constructors

Constructor

new BrowseError(
code: BrowseErrorCode,
message: string,
resolution?: {
label: string;
url: string;
}
): BrowseError;

Defined in: packages/media-session/src/browse.ts:87

Parameters

ParameterTypeDescription
codeBrowseErrorCode-
messagestring-
resolution?{ label: string; url: string; }An optional button under the message: a label and a deep link your app handles. The phone opens the URL; the car cannot render your sign-in form itself.
resolution.label?string-
resolution.url?string-

Returns

BrowseError

Overrides

Error.constructor

Properties

cause?

optional cause?: unknown;

Defined in: website/node_modules/typescript/lib/lib.es2022.error.d.ts:26

Inherited from

Error.cause

code

readonly code: BrowseErrorCode;

Defined in: packages/media-session/src/browse.ts:88


message

message: string;

Defined in: website/node_modules/typescript/lib/lib.es5.d.ts:1077

Inherited from

Error.message

name

readonly name: "BrowseError" = 'BrowseError';

Defined in: packages/media-session/src/browse.ts:85

Always 'BrowseError', and load-bearing: isBrowseError tests this rather than instanceof, so an error thrown by a copy of this package inside a monorepo (or across a bundle boundary) is still recognised.

Overrides

Error.name

resolution?

readonly optional resolution?: {
label: string;
url: string;
};

Defined in: packages/media-session/src/browse.ts:95

An optional button under the message: a label and a deep link your app handles. The phone opens the URL; the car cannot render your sign-in form itself.

label

label: string;

url

url: string;

stack?

optional stack?: string;

Defined in: website/node_modules/typescript/lib/lib.es5.d.ts:1078

Inherited from

Error.stack

stackTraceLimit

static stackTraceLimit: number;

Defined in: node_modules/@types/node/globals.d.ts:67

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

Error.stackTraceLimit

Methods

captureStackTrace()

static captureStackTrace(targetObject: object, constructorOpt?: Function): void;

Defined in: node_modules/@types/node/globals.d.ts:51

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

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:

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

ParameterType
targetObjectobject
constructorOpt?Function

Returns

void

Inherited from

Error.captureStackTrace

isError()

static isError(error: unknown): error is Error;

Defined in: website/node_modules/typescript/lib/lib.esnext.error.d.ts:23

Indicates whether the argument provided is a built-in Error instance or not.

Parameters

ParameterType
errorunknown

Returns

error is Error

Inherited from

Error.isError

prepareStackTrace()

static prepareStackTrace(err: Error, stackTraces: CallSite[]): any;

Defined in: node_modules/@types/node/globals.d.ts:55

Parameters

ParameterType
errError
stackTracesCallSite[]

Returns

any

See

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

Inherited from

Error.prepareStackTrace