import {strict as assert} from 'assert' export class FlashAuditError extends Error { errorCode: string constructor( message:string , errorCode:string = '') { super(message) this.errorCode = errorCode; } extra (extraMessage:string) : FlashAuditError { return new FlashAuditError(`${this.message}:\n${extraMessage}`,this.errorCode); } } export const allErrors = { generic_error: new FlashAuditError('Unspecified error'), server_timedout: new FlashAuditError('Timed out awaiting server response'), producer_disconnected: new FlashAuditError("Producer client isn't connected."), invalid_format: new FlashAuditError("Audit format is not valid."), unauthorized: new FlashAuditError("Unauthorized request."), broker_error: new FlashAuditError("Unknown broker error."), broker_unavailable: new FlashAuditError("Broker unavailable.") }; for (let key of Object.keys(allErrors)) { ((allErrors as any)[key] as FlashAuditError).errorCode = key; }