import { Feedback } from "./feedback" ; export class MyError { public Message : string ; public Code : string ; public Inner : MyError ; public constructor ( init ? ) { Object . assign ( this , init ) ; } public getPretty ( ) { return this . Message ; } } export class MyExecError extends MyError { public Program : string ; public constructor ( init ? ) { super ( ) ; Object . assign ( this , init ) ; } public getPretty ( ) { return `[${ this . Program }] said ${ this . Message } (code = ${ this . Code })` ; } } export class MyHttpError extends MyError { public Url : string ; public RequestError : Error ; public constructor ( init ? ) { super ( ) ; Object . assign ( this , init ) ; } public getPretty ( ) { let requestErrorPretty = this . RequestError ? this . RequestError . message : "" ; return `${ this . Url }, code = ${ this . Code }, ${ this . Message }, ${ requestErrorPretty }` ; } } export class MySetupError extends MyError { } export function caughtTopLevel ( originalError ) { if ( originalError instanceof Error ) { Feedback . error ( originalError . message ) ; return ; } let chain = [ ] ; chain . push ( originalError ) ; let error = originalError ; while ( error . Inner ) { error = error . Inner ; chain . push ( error ) ; } let summary = originalError . getPretty ( ) ; let detailedBuilder = [ ] ; chain . forEach ( function ( item ) { let errorType = item . constructor . name ; let pretty = item . getPretty ( ) ; detailedBuilder . push ( `[${ errorType }]: ${ pretty }` ) ; } ) ; let detailed = detailedBuilder . join ( "...\n" ) ; Feedback . error ( summary , detailed , [ "default" ] ) ; }