-
Notifications
You must be signed in to change notification settings - Fork 668
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: only generate stack on HttpError if status >= 500 (#2470)
- Loading branch information
1 parent
8865d29
commit bd60444
Showing
2 changed files
with
8 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,12 @@ | ||
import { expect } from "@std/expect"; | ||
import { MODE, setMode } from "./runtime/server/mod.tsx"; | ||
import { HttpError } from "./error.ts"; | ||
|
||
Deno.test("HttpError - contains stack in development", () => { | ||
const tmp = MODE; | ||
setMode("development"); | ||
try { | ||
const err = new HttpError(404); | ||
expect(err.status).toEqual(404); | ||
expect(typeof err.stack).toEqual("string"); | ||
} finally { | ||
setMode(tmp); | ||
} | ||
}); | ||
Deno.test("HttpError - contains stack if error >=500", () => { | ||
const err = new HttpError(404); | ||
expect(err.status).toEqual(404); | ||
expect(typeof err.stack).toEqual("undefined"); | ||
|
||
Deno.test("HttpError - contains no stack in production", () => { | ||
const tmp = MODE; | ||
setMode("production"); | ||
try { | ||
const err = new HttpError(404); | ||
expect(err.status).toEqual(404); | ||
expect(err.stack).toEqual(undefined); | ||
} finally { | ||
setMode(tmp); | ||
} | ||
const err2 = new HttpError(500); | ||
expect(err2.status).toEqual(500); | ||
expect(typeof err2.stack).toEqual("string"); | ||
}); |