Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/FoxxMD/multi-scrobbler. Scrobble plays from multiple sources to multiple clients docs.multi-scrobbler.app
deezer docker jellyfin koito lastfm listenbrainz maloja mopidy mpris music music-assistant plex scrobble self-hosted spotify subsonic tautulli youtube-music
Something went wrong. Try again.
1.9 kB · 59 lines
TypeScript
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859import { isAbortError } from "abort-controller-x";import { getErrorCause } from "../../core/ErrorUtils.ts";
/** * Adapted from https://github.com/voxpelli/pony-cause/blob/main/lib/helpers.js to find cause by truthy function * */export const findCauseByFunc = <T extends Error = Error>(err: any, func: (e: Error) => boolean): T | undefined => { if (!err || !func) return; if (!(err instanceof Error)) return; if (typeof func !== 'function') { return; }
/** * Ensures we don't go circular */ const seen = new Set<Error>();
let currentErr: Error | undefined = err;
while (currentErr && !seen.has(currentErr)) { seen.add(currentErr);
if (func(currentErr)) { return currentErr as T; }
currentErr = getErrorCause(currentErr) as unknown as T; }};export const findCauseByMessage = (err: any, msg: string) => { return findCauseByFunc(err, (e => e.message.toLocaleLowerCase().includes(msg.toLocaleLowerCase())));}/** * Adapted from https://github.com/voxpelli/pony-cause * */export const findCauseByReference = <T extends Error>(err: unknown, reference: new (...args: any[]) => T): T | undefined => { if (!err || !reference) return; if (!(err instanceof Error)) return; if (!(reference.prototype instanceof Error) && // @ts-expect-error we are purposely checking if ref is generic error class reference !== Error) return;
const seen = new Set();
let currentErr = err;
while (currentErr && !seen.has(currentErr)) { seen.add(currentErr);
if (currentErr instanceof reference) { return currentErr; }
currentErr = getErrorCause(currentErr) as unknown as T; }};
export const isAbortReasonErrorLike = (signal: AbortSignal) => signal.aborted && signal.reason !== undefined && (isAbortError(signal.reason) || signal.reason instanceof Error);