feat: expose HttpError for clients (#3080)
This PR exposes the `HttpError` class for clients. To do that I needed to make the error message optional to avoid bloating up the bundle with lots of status strings. Fixes https://github.com/denoland/fresh/issues/2995 --------- Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
This commit is contained in:
co-authored by
Bartek Iwańczuk
parent
0fff2b04da
commit
882b7829fd
@@ -4,11 +4,20 @@ 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");
|
||||
});
|
||||
|
||||
Deno.test("HttpError - message", () => {
|
||||
const err = new HttpError(500, "foo");
|
||||
expect(err.message).toEqual("foo");
|
||||
});
|
||||
|
||||
Deno.test("HttpError - cause", () => {
|
||||
const causeErr = new Error();
|
||||
const err = new HttpError(500, "foo", { cause: causeErr });
|
||||
expect(err.cause).toEqual(causeErr);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user