This repository was archived by the owner on Aug 27, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 5 files changed +14
-25
lines changed
Expand file tree Collapse file tree 5 files changed +14
-25
lines changed Original file line number Diff line number Diff line change 88Enjoy 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
1414ErrorCode [404 ]; // NOT_FOUND
1515ErrorCode .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// ->
2222error .status ; // 404
Original file line number Diff line number Diff line change 11{
22 "name" : " @wvm/http-error" ,
3- "version" : " 2 .0.0" ,
3+ "version" : " 3 .0.0" ,
44 "publish" : {
55 "exclude" : [" .github" ]
66 },
Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff line change 11export { ErrorCode } from "./codes.ts" ;
22export { HttpError } from "./error.ts" ;
3- export { raise } from "./raise.ts" ;
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments