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:
+4
-2
@@ -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");
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user