1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-23 07:44:48 -05:00
denoland-deno/js/errors.ts
Ryan Dahl 18d495c7d1 Better error handling in src/handlers.rs
Introduces error codes that are shared between JS/RS

Fixes #526.
2018-08-21 15:37:45 -04:00

15 lines
412 B
TypeScript

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