refactor(core): standardize HttpError (#2858)

- 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.
This commit is contained in:
Asher Gomez
2025-04-27 20:01:31 +02:00
committed by GitHub
parent 5876ca7752
commit 7aec5a268e
4 changed files with 39 additions and 1638 deletions
+4 -2
View File
@@ -1,12 +1,14 @@
import { expect } from "@std/expect";
import { HttpError } from "./error.ts";
Deno.test("HttpError - contains stack if error >=500", () => {
Deno.test("HttpError", () => {
const err = new HttpError(404);
expect(err.status).toEqual(404);
expect(typeof err.stack).toEqual("undefined");
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");
});