import { inspect } from 'util' ; /**
 * Produce a string version of an error,
 */ function formatErrorMessage ( error ) { if ( typeof error === 'string' ) { return error ; } if ( ! error ) { return inspect ( error ) ; } if ( error . resp && error . resp . error && error . resp . error . root_cause ) { return error . resp . error . root_cause . map ( ( cause ) => cause . reason ) . join ( '\n' ) ; } if ( error . body && typeof error . body . message === 'string' ) { return error . body . message ; } if ( error instanceof Error && error . message ) { return error . message ; } return inspect ( error ) ; } /**
 * Format the stack trace from a message so that it setups with the message, which
 * some browsers do automatically and some don't
 */ function formatStack ( err ) { if ( err . stack && ! err . stack . includes ( err . message ) ) { return 'Error: ' + err . message + '\n' + err . stack ; } return err . stack ; } /**
 * Produce a simple FatalErrorInfo object from some error and optional source, used for
 * displaying error information on the fatal error screen
 */ export function getErrorInfo ( error , source ? ) { const prefix = source ? source + ': ' : '' ; return { message : prefix + formatErrorMessage ( error ) , stack : formatStack ( error ) , } ; } public export interface FatalErrorInfo { message : string ; stack : string | undefined ; }