diff options
author | Matěj Cepl <mcepl@cepl.eu> | 2023-01-11 09:37:51 +0100 |
---|---|---|
committer | Matěj Cepl <mcepl@cepl.eu> | 2023-01-11 09:37:51 +0100 |
commit | ad3932128a6b98d93f4a64c0bac67112b89c33e2 (patch) | |
tree | e40839c5b587aea240bc3d42b757777678aeb62b /lib | |
parent | bed92eae10558cdd8eddfd91f5d8addaf509413c (diff) | |
download | jsCalDAV-typescript.tar.gz |
Add documentationHEADtypescript
Diffstat (limited to 'lib')
-rw-r--r-- | lib/caldav/errors.ts | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/lib/caldav/errors.ts b/lib/caldav/errors.ts new file mode 100644 index 0000000..1b58a6f --- /dev/null +++ b/lib/caldav/errors.ts @@ -0,0 +1,40 @@ +(function(module, ns) { + + Errors = {}; + + /** + * Errors typically are for front-end routing purposes so the important + * part really is just the name and (maybe) the symbol... These are really + * intended to be consumed by name... So once a name has been assigned it + * should never be modified. + */ + [ + { symbol: 'Authentication', name: 'authentication' }, + { symbol: 'InvalidEntrypoint', name: 'invalid-entrypoint' }, + { symbol: 'ServerFailure', name: 'server-failure' }, + { symbol: 'Unknown', name: 'unknown' } + ].forEach(function createError(def) { + var obj = Errors[def.symbol] = function(message) { + this.message = message; + this.name = 'caldav-' + def.name; + + try { + throw new Error(); + } catch (e) { + this.stack = e.stack; + } + }; + + // just so instanceof Error works + obj.prototype = Object.create(Error.prototype); + }); + + module.exports = Errors; + +}.apply( + this, + (this.Caldav) ? + [Caldav('errors'), Caldav] : + [module, require('./caldav')] +)); + |