summaryrefslogtreecommitdiff
path: root/js/errors.ts
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2018-08-15 23:36:48 -0400
committerRyan Dahl <ry@tinyclouds.org>2018-08-21 15:37:45 -0400
commit18d495c7d17cf3fce3835e732094d058f51eddaa (patch)
treef7244cfd83dbff9d8aaf67203feb0f3a24fe95f3 /js/errors.ts
parentcb1393cdaea4bfbee69efbf7ce86a4adfc4593b3 (diff)
Better error handling in src/handlers.rs
Introduces error codes that are shared between JS/RS Fixes #526.
Diffstat (limited to 'js/errors.ts')
-rw-r--r--js/errors.ts15
1 files changed, 15 insertions, 0 deletions
diff --git a/js/errors.ts b/js/errors.ts
new file mode 100644
index 000000000..2fca10eaf
--- /dev/null
+++ b/js/errors.ts
@@ -0,0 +1,15 @@
+import { deno as fbs } from "gen/msg_generated";
+
+export class DenoError<T extends fbs.ErrorKind> extends Error {
+ constructor(readonly kind: T, msg: string) {
+ super(msg);
+ this.name = `deno.${fbs.ErrorKind[kind]}`;
+ }
+}
+
+export function maybeThrowError(base: fbs.Base): void {
+ const kind = base.errorKind();
+ if (kind !== fbs.ErrorKind.NoError) {
+ throw new DenoError(kind, base.error()!);
+ }
+}