format export function isAuthError ( err ) { return ( err instanceof UserNotSignedInError || err instanceof UserUnauthorizedError ) ; } export function isConnectivityOrAuthError ( err ) { return ( err instanceof ConnectivityError || isAuthError ( err ) || String ( err ) . startsWith ( 'Failed to fetch' ) || String ( err ) . endsWith ( 'Failed to fetch' ) ) ; } export class CancelledPromiseError extends Error { constructor ( msg ) { super ( msg ) ; this . name = 'CancelledPromiseError' ; } name : 'CancelledPromiseError' ; } export class ConnectivityError extends Error { constructor ( msg ) { super ( msg ) ; this . name = 'ConnectivityError' ; } name : 'ConnectivityError' ; } export class UserUnauthorizedError extends Error { constructor ( msg = 'User unauthorized.' ) { super ( msg ) ; this . name = 'UserUnauthorizedError' ; } name : 'UserUnauthorizedError' ; } export class UserNotSignedInError extends Error { constructor ( msg = 'User not signed in.' ) { super ( msg ) ; this . name = 'UserNotSignedInError' ; } name : 'UserNotSignedInError' ; } export class NoLongerConnectedToClientError extends Error { constructor ( msg = 'No longer connected to client.' ) { super ( msg ) ; this . name = 'NoLongerConnectedToClientError' ; } name : 'NoLongerConnectedToClientError' ; } declare global { interface Error { interaction ? : unknown ; } } export function isError ( obj ) { return ( obj instanceof Error || ( obj && obj . name && typeof obj . name === 'string' && obj . message && typeof obj . message === 'string' && obj . stack && typeof obj . stack === 'string' ) ) ; } export function getErrorFromErrorLike ( e ) { if ( Array . isArray ( e ) ) { return e . map ( getErrorFromErrorLike ) . find ( ( x ) => x ) ; } else if ( isError ( e ) ) { return e ; } else { return undefined ; } } export function getStringFromErrorLike ( e ) { if ( Array . isArray ( e ) ) { return e . map ( getStringFromErrorLike ) . join ( ' ' ) ; } else if ( typeof e == 'string' ) { return e ; } else if ( isError ( e ) ) { return e . message || e . toString ( ) ; } else { try { return JSON . stringify ( e ) ; } catch ( e ) { return '' + e ; } } }