export const DEFAULT_DISPLAY_MESSAGE = 'Sorry, something went wrong.' ; export type ExtendedError = Error & ExtendedErrorAttributes ; type ExtendedErrorAttributes = Record < string , any > & { displayMessage ? : string ; code ? : number | string ; } ; export function createError ( message ? , attributes = { } ) { const error = new Error ( message ) as ExtendedError ; for ( const [ name , value ] of Object . entries ( attributes ) ) { if ( value !== undefined ) { error [ name ] = value ; } } return error ; } export function throwError ( message ? , attributes = { } ) { throw createError ( message , attributes ) ; } export function formatError ( error ? , { defaultDisplayMessage = DEFAULT_DISPLAY_MESSAGE } = { } ) { return error ?. displayMessage ?? defaultDisplayMessage ; }