diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2018-08-15 23:36:48 -0400 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2018-08-21 15:37:45 -0400 |
commit | 18d495c7d17cf3fce3835e732094d058f51eddaa (patch) | |
tree | f7244cfd83dbff9d8aaf67203feb0f3a24fe95f3 /js/errors.ts | |
parent | cb1393cdaea4bfbee69efbf7ce86a4adfc4593b3 (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.ts | 15 |
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()!); + } +} |