import { GQLError , ServerInternalError } from '@cloudbeaver/core-sdk' ; export interface IErrorInfo { message : string ; stackTrace : string ; } export interface IErrorModelOptions { reason ? : string ; error ? : Error ; } export class ErrorModel { reason : string ; errors : IErrorInfo [ ] = [ ] ; textToCopy = '' ; htmlBody = '' ; constructor ( { reason , error } ) { this . reason = reason || '' ; if ( ! error ) { this . textToCopy = this . reason ; } else if ( error instanceof GQLError ) { this . errors = ( error . response ?. errors || [ ] ) . map ( error => { const errorInfo = { message : error . message , stackTrace : error . extensions ?. stackTrace || '' , } ; return errorInfo ; } ) ; this . textToCopy = error . isTextBody ? error . errorMessage : this . textToCopy = this . errors . map ( error => `${ error . message }\n${ error . stackTrace }` ) . join ( '------------------\n' ) ; if ( error . isTextBody ) { this . htmlBody = error . errorMessage ; } } else if ( error instanceof ServerInternalError ) { this . errors = [ { message : error . message , stackTrace : error . stackTrace || '' , } , ] ; this . textToCopy = `${ error . message }\n${ error . stackTrace }` ; } else if ( error instanceof Error ) { this . errors = [ { message : error . message , stackTrace : error . stack || '' , } , ] ; this . textToCopy = `${ error . message }\n${ error . stack }` ; } } }