From 18d495c7d17cf3fce3835e732094d058f51eddaa Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Wed, 15 Aug 2018 23:36:48 -0400 Subject: Better error handling in src/handlers.rs Introduces error codes that are shared between JS/RS Fixes #526. --- js/errors.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 js/errors.ts (limited to 'js/errors.ts') 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 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()!); + } +} -- cgit v1.2.3