- Now extends `Error`, so that it satisfies `instanceof Error` operations. - Narrows the `status` property to be an actual HTTP status code. - Outsources default evaluation of the `message` property to `@std/http/status`, which already implements this functionality. - Brings the `stack` property to the class, regardless of its status, which seems like a needless constraint.
15 lines
449 B
TypeScript
15 lines
449 B
TypeScript
import { expect } from "@std/expect";
|
|
import { HttpError } from "./error.ts";
|
|
|
|
Deno.test("HttpError", () => {
|
|
const err = new HttpError(404);
|
|
expect(err.status).toEqual(404);
|
|
expect(err.message).toEqual("Not Found");
|
|
expect(typeof err.stack).toEqual("string");
|
|
|
|
const err2 = new HttpError(500);
|
|
expect(err2.status).toEqual(500);
|
|
expect(err2.message).toEqual("Internal Server Error");
|
|
expect(typeof err2.stack).toEqual("string");
|
|
});
|