summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Van Doorn <vandoorn.nick@gmail.com>2019-01-19 20:57:44 -0800
committerNick Van Doorn <vandoorn.nick@gmail.com>2019-01-19 20:57:44 -0800
commitfaa4fb49cc7ec1eeab49a6dc5d43899a8a2cd20b (patch)
tree8b216251565d4a83e576fcede47e8a7a8b4e3a6c
parentba9af27c334ccca539aa243a081c744fdb042bc0 (diff)
Define custom error type
-rw-r--r--src/error.model.ts22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/error.model.ts b/src/error.model.ts
new file mode 100644
index 0000000..5cf9916
--- /dev/null
+++ b/src/error.model.ts
@@ -0,0 +1,22 @@
+export enum NaiveErrorCode {
+ UNCAUGHT = 0,
+ OUT_OF_SPACE
+}
+
+const e = NaiveErrorCode;
+
+export const lookupMsg = (c: NaiveErrorCode) => {
+ switch (c) {
+ case e.OUT_OF_SPACE:
+ return `Out of storage space (too big for in memory buffer)`;
+ case e.UNCAUGHT:
+ default:
+ return `Uncaught error. Please add message/code in src/error.model.ts`;
+ }
+};
+
+export class NaiveError extends Error {
+ constructor(public code: NaiveErrorCode) {
+ super(lookupMsg(code));
+ }
+}