Files

1 line
30 KiB
Plaintext
Raw Permalink Normal View History

2026-03-12 12:47:56 +08:00
{"version":3,"file":"index.cjs","sources":["../src/errors.ts","../src/EventSource.ts"],"sourcesContent":["/**\n * An extended version of the `Event` emitted by the `EventSource` object when an error occurs.\n * While the spec does not include any additional properties, we intentionally go beyond the spec\n * and provide some (minimal) additional information to aid in debugging.\n *\n * @public\n */\nexport class ErrorEvent extends Event {\n /**\n * HTTP status code, if this was triggered by an HTTP error\n * Note: this is not part of the spec, but is included for better error handling.\n *\n * @public\n */\n public code?: number | undefined\n\n /**\n * Optional message attached to the error.\n * Note: this is not part of the spec, but is included for better error handling.\n *\n * @public\n */\n public message?: string | undefined\n\n /**\n * Constructs a new `ErrorEvent` instance. This is typically not called directly,\n * but rather emitted by the `EventSource` object when an error occurs.\n *\n * @param type - The type of the event (should be \"error\")\n * @param errorEventInitDict - Optional properties to include in the error event\n */\n constructor(\n type: string,\n errorEventInitDict?: {message?: string | undefined; code?: number | undefined},\n ) {\n super(type)\n this.code = errorEventInitDict?.code ?? undefined\n this.message = errorEventInitDict?.message ?? undefined\n }\n\n /**\n * Node.js \"hides\" the `message` and `code` properties of the `ErrorEvent` instance,\n * when it is `console.log`'ed. This makes it harder to debug errors. To ease debugging,\n * we explicitly include the properties in the `inspect` method.\n *\n * This is automatically called by Node.js when you `console.log` an instance of this class.\n *\n * @param _depth - The current depth\n * @param options - The options passed to `util.inspect`\n * @param inspect - The inspect function to use (prevents having to import it from `util`)\n * @returns A string representation of the error\n */\n [Symbol.for('nodejs.util.inspect.custom')](\n _depth: number,\n options: {colors: boolean},\n inspect: (obj: unknown, inspectOptions: {colors: boolean}) => string,\n ): string {\n return inspect(inspectableError(this), options)\n }\n\n /**\n * Deno \"hides\" the `message` and `code` properties of the `ErrorEvent` instance,\n * when it is `console.log`'ed. This makes it harder to debug errors. To ease debugging,\n * we explicitly include the properties in the `inspect` method.\n *\n * This is automatically called by Deno when you `console.log` an instance of this class.\n *\n * @param inspect - The inspect function to use (prevents having to import it from `util`)\n * @param options - The options passed to `Deno.inspect`\n * @returns A string representation of the error\n */\n [Symbol.for('Deno.customInspect')](\n inspect: (obj: unknown, inspectOptions: {colors: boolean}) => string,\n options: {colors: boolean},\n ): string {\n return inspect(inspectableError(this), options)\n }\n}\n\n/**\n * For environments where DOMException may not exist, we will use a SyntaxError instead.\n * While this isn't strictly according to spec, it is very close.\n *\n * @param message - The message to include in the error\n * @returns A `DOMException` or `SyntaxError` instance\n * @internal\n */\nexport function syntaxError(message: string): SyntaxError {\n // If someone can figure out a way to make this work without depending on DOM/Node.js typings,\n // and without casting to `any`, please send a PR 🙏\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const DomException = (globalThis as any).DOMException\n if (typeof DomException === 'function') {\n return new DomException(message, 'SyntaxError')\n }\n\n return new SyntaxError(message)\n}\n\n/**\n * Flatten an error into a single error message string.\n * Unwraps nested errors and joins them with a comma.\n *\n * @param err - The error to flatten\n * @returns A string