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>
24 lines
650 B
TypeScript
24 lines
650 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(typeof err.stack).toEqual("string");
|
|
|
|
const err2 = new HttpError(500);
|
|
expect(err2.status).toEqual(500);
|
|
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);
|
|
});
|