diff options
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()!); + } +} |