Skip to content
This repository was archived by the owner on Aug 27, 2025. It is now read-only.

Commit 7e1f0ab

Browse files
committed
v3.0.0! abandon tagged fn
1 parent f47f221 commit 7e1f0ab

File tree

5 files changed

+14
-25
lines changed

5 files changed

+14
-25
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
Enjoy hassle-free HTTP error status handling:
99

1010
```ts
11-
import { ErrorCode, HttpError, raise } from "@wvm/http-error";
11+
import { ErrorCode, HttpError } from "@wvm/http-error";
1212

13-
// ErrorCode Mapper
13+
// Map ErrorCode
1414
ErrorCode[404]; // NOT_FOUND
1515
ErrorCode.NOT_FOUND; // 404
1616

17-
// HttpError Raiser
18-
throw raise(404)`Missing Page`;
19-
throw raise("NOT_FOUND")`Missing Page`;
17+
// Get HttpError
18+
throw new HttpError(404, "Missing Page");
19+
throw new HttpError("NOT_FOUND", "Missing Page");
2020

2121
// ->
2222
error.status; // 404

deno.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@wvm/http-error",
3-
"version": "2.0.0",
3+
"version": "3.0.0",
44
"publish": {
55
"exclude": [".github"]
66
},

src/error.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,15 @@ export class HttpError extends Error {
1515

1616
/**
1717
* @param error HTTP Error Code/Phrase
18-
* @param message HTTP Error Details
18+
* @param message HTTP Error Message
1919
*/
20-
constructor(error: ErrorCode | keyof typeof ErrorCode, message: string) {
21-
super(message);
20+
constructor(error: ErrorCode | keyof typeof ErrorCode, message?: string) {
21+
const status = typeof error === "number" ? error : ErrorCode[error];
22+
const phrase = typeof error === "number" ? ErrorCode[error] : error;
2223

23-
this.status = typeof error === "number" ? error : ErrorCode[error];
24-
this.phrase = typeof error === "number" ? ErrorCode[error] : error;
24+
super(message ?? `${status} ${phrase}`);
25+
26+
this.status = status;
27+
this.phrase = phrase;
2528
}
2629
}

src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
export { ErrorCode } from "./codes.ts";
22
export { HttpError } from "./error.ts";
3-
export { raise } from "./raise.ts";

src/raise.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)