UNPKG

@thisisagile/easy

Version:

Straightforward library for building domain-driven microservice architectures

1 lines 2.55 kB
{"version":3,"sources":["../src/types/Exception.ts"],"sourcesContent":["import { asString, Text } from './Text';\nimport { Enum } from './Enum';\nimport { isDefined } from './Is';\nimport { Id } from './Id';\nimport { text } from './Template';\n\nexport class Exception extends Enum {\n static readonly AlreadyExists = new Exception('Subject already exists');\n static readonly DoesNotExist = new Exception('Does not exist');\n static readonly IsMissingId = new Exception('Subject is missing an id');\n static readonly IsNotImplemented = new Exception('Is not implemented');\n static readonly IsNotValid = new Exception('Is not valid');\n static readonly Unknown = new Exception('Unknown error');\n\n constructor(\n readonly message: string,\n id?: Id,\n readonly reason?: Text\n ) {\n super(message, id ?? text(message).pascal.toString());\n }\n\n static readonly CouldNotExecute = (target: Text): Exception => new Exception(`Could not execute ${target}.`, 'CouldNotExecute');\n\n static readonly CouldNotValidate = (target: Text): Exception => new Exception(`Could not validate ${target}.`, 'CouldNotValidate');\n\n static readonly EnvironmentVariableNotFound = (variable: Text): Exception =>\n new Exception(`Environment variable ${text(variable).upper} could not be found.`, 'EnvironmentVariableNotFound');\n\n because = (reason: Text): Exception => new Exception(this.message, this.id, reason);\n}\n\nexport const isException = (e?: unknown, t?: Text): e is Exception => e instanceof Exception && (isDefined(t) ? e.equals(asString(t)) : true);\nexport const isDoesNotExist = (e?: unknown): e is Exception => e instanceof Exception && Exception.DoesNotExist.equals(e);\n"],"mappings":";;;;;;;;;;;;;;AAMO,IAAM,YAAN,MAAM,mBAAkB,KAAK;AAAA,EAQlC,YACW,SACT,IACS,QACT;AACA,UAAM,SAAS,MAAM,KAAK,OAAO,EAAE,OAAO,SAAS,CAAC;AAJ3C;AAEA;AAAA,EAGX;AAAA,EAbA,OAAgB,gBAAgB,IAAI,WAAU,wBAAwB;AAAA,EACtE,OAAgB,eAAe,IAAI,WAAU,gBAAgB;AAAA,EAC7D,OAAgB,cAAc,IAAI,WAAU,0BAA0B;AAAA,EACtE,OAAgB,mBAAmB,IAAI,WAAU,oBAAoB;AAAA,EACrE,OAAgB,aAAa,IAAI,WAAU,cAAc;AAAA,EACzD,OAAgB,UAAU,IAAI,WAAU,eAAe;AAAA,EAUvD,OAAgB,kBAAkB,CAAC,WAA4B,IAAI,WAAU,qBAAqB,MAAM,KAAK,iBAAiB;AAAA,EAE9H,OAAgB,mBAAmB,CAAC,WAA4B,IAAI,WAAU,sBAAsB,MAAM,KAAK,kBAAkB;AAAA,EAEjI,OAAgB,8BAA8B,CAAC,aAC7C,IAAI,WAAU,wBAAwB,KAAK,QAAQ,EAAE,KAAK,wBAAwB,6BAA6B;AAAA,EAEjH,UAAU,CAAC,WAA4B,IAAI,WAAU,KAAK,SAAS,KAAK,IAAI,MAAM;AACpF;AAEO,IAAM,cAAc,CAAC,GAAa,MAA6B,aAAa,cAAc,UAAU,CAAC,IAAI,EAAE,OAAO,SAAS,CAAC,CAAC,IAAI;AACjI,IAAM,iBAAiB,CAAC,MAAgC,aAAa,aAAa,UAAU,aAAa,OAAO,CAAC;","names":[]}