mirror of
https://github.com/denoland/deno.git
synced 2024-12-23 07:44:48 -05:00
8090fb252b
Originally we planned to have a JS class for each error code. But it seems better to just have a single DenoError class with a "kind" property. One nice thing about using an enum instead of classes for errors is that switch() can be used during error handling instead of a bunch of instanceof branches.
20 lines
632 B
TypeScript
20 lines
632 B
TypeScript
// Copyright 2018 the Deno authors. All rights reserved. MIT license.
|
|
import { test, testPerm, assert, assertEqual } from "./test_util.ts";
|
|
import * as deno from "deno";
|
|
|
|
testPerm({ net: true }, async function fetchJsonSuccess() {
|
|
const response = await fetch("http://localhost:4545/package.json");
|
|
const json = await response.json();
|
|
assertEqual(json.name, "deno");
|
|
});
|
|
|
|
test(async function fetchPerm() {
|
|
let err;
|
|
try {
|
|
await fetch("http://localhost:4545/package.json");
|
|
} catch (err_) {
|
|
err = err_;
|
|
}
|
|
assertEqual(err.kind, deno.ErrorKind.PermissionDenied);
|
|
assertEqual(err.name, "PermissionDenied");
|
|
});
|