1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-23 15:16:54 -05:00
denoland-deno/js/errors.ts
2018-09-05 08:45:55 -04:00

17 lines
438 B
TypeScript

import { deno as fbs } from "gen/msg_generated";
// @internal
export class DenoError<T extends fbs.ErrorKind> extends Error {
constructor(readonly kind: T, msg: string) {
super(msg);
this.name = `deno.${fbs.ErrorKind[kind]}`;
}
}
// @internal
export function maybeThrowError(base: fbs.Base): void {
const kind = base.errorKind();
if (kind !== fbs.ErrorKind.NoError) {
throw new DenoError(kind, base.error()!);
}
}