@@ -16,24 +16,23 @@ It provides:
1616
1717- Custom error classes (` NotFoundError ` , ` BadRequestError ` , ` ValidationError ` , etc.)
1818- Express middleware: ` globalErrorHandler ` , ` notFoundHandler `
19- - An ` asyncHandler ` utility to catch async route errors without boilerplate
20- - A flexible ` httpError() ` factory function
21- - ` isCustomAPIError() ` type guard for better type safety
19+ - An ` asyncHandler ` utility to handle async errors without boilerplate
20+ - A ` httpError() ` factory function to create custom error instances easily
21+ - ` isCustomAPIError() ` type guard for safe error type checks
2222- Re-exported utilities from [ ` http-status-toolkit ` ] ( https://www.npmjs.com/package/http-status-toolkit ) — no need to install it separately
2323
2424---
2525
2626## ✨ Features
2727
2828- ✅ Type-safe custom error classes
29- - ✅ Centralized global error handler
29+ - ✅ Centralized error-handling middleware
3030- ✅ Async error wrapper for route handlers
31- - ✅ Built-in 404 handler for unknown routes
32- - ✅ ` httpError() ` factory for dynamic error creation
33- - ✅ ` isCustomAPIError() ` type guard for safe narrowing
34- - ✅ Includes ` http-status-toolkit ` exports (like ` StatusCodes ` )
35- - ✅ Works with both CommonJS and ESM
36- - ✅ First-class TypeScript support
31+ - ✅ Built-in 404 (Not Found) handler
32+ - ✅ Factory method for generating custom errors
33+ - ✅ Type guard for runtime error checking
34+ - ✅ Out-of-the-box support for both CJS and ESM
35+ - ✅ Includes ` http-status-toolkit ` exports (like ` StatusCodes ` , ` getStatusMessage ` )
3736
3837---
3938
@@ -104,7 +103,29 @@ In development mode (`NODE_ENV=development`), the error stack trace will be incl
104103
105104---
106105
107- ### 5. ** Bonus** : Use status codes directly (re-exported from http-status-toolkit)
106+ ### 5. ** httpError()** : Create generic custom errors
107+
108+ ``` ts
109+ import { httpError } from ' express-error-toolkit' ;
110+
111+ throw httpError (' Something custom' , 418 );
112+ ```
113+
114+ ---
115+
116+ ### 6. ** isCustomAPIError()** : Type guard for checking error type
117+
118+ ``` ts
119+ import { isCustomAPIError } from ' express-error-toolkit' ;
120+
121+ if (isCustomAPIError (err )) {
122+ console .log (err .statusCode , err .message );
123+ }
124+ ```
125+
126+ ---
127+
128+ ### 7. ** Bonus** : Use status codes directly (re-exported from http-status-toolkit)
108129
109130``` ts
110131import { StatusCodes , getStatusMessage } from ' express-error-toolkit' ;
@@ -118,21 +139,45 @@ res.status(StatusCodes.BAD_REQUEST).json({
118139
119140## 🔧 Custom Error Classes Available
120141
121- | Error Class | Default Message | Status Code |
122- | ----------------- | --------------- | ----------- |
123- | ` NotFoundError ` | "Not Found" | ` 404 ` |
124- | ` BadRequestError ` | "Bad Request" | ` 400 ` |
142+ | Error Class | Default Message | Status Code |
143+ | ------------------------| -------------------------| -------------|
144+ | ` BadRequestError ` | Bad Request | ` 400 ` |
145+ | ` UnauthorizedError ` | Unauthorized | ` 401 ` |
146+ | ` ForbiddenError ` | Forbidden | ` 403 ` |
147+ | ` NotFoundError ` | Not Found | ` 404 ` |
148+ | ` ConflictError ` | Conflict | ` 409 ` |
149+ | ` ValidationError ` | Unprocessable Entity | ` 422 ` |
150+ | ` TooManyRequestsError ` | Too Many Requests | ` 429 ` |
151+ | ` CustomAPIError ` | Internal Server Error | ` 500 ` |
125152
126- _ (More to be added in future updates)_
153+ ---
154+
155+ ## 📂 Directory Structure
156+
157+ ```
158+ ├── src/
159+ │ ├── error/
160+ │ │ ├── BadRequestError.ts
161+ │ │ ├── NotFoundError.ts
162+ │ │ └── ...
163+ │ ├── global-error-handler.ts
164+ │ ├── async-handler.ts
165+ │ ├── http-error.ts
166+ │ └── index.ts
167+ ├── example/
168+ │ └── index.ts
169+ ├── __tests__/
170+ │ └── *.test.ts
171+ ```
127172
128173---
129174
130175## 🛠 Build & Compatibility
131176
132177- Fully written in TypeScript
133178- Outputs:
134- - CommonJS: ` dist/index.cjs.js `
135- - ESM: ` dist/index.esm. js `
179+ - CommonJS: ` dist/index.cjs `
180+ - ESM: ` dist/index.js `
136181 - Types: ` dist/index.d.ts `
137182
138183---
@@ -146,3 +191,17 @@ MIT © [Rashedin Islam](https://www.rashedin.dev)
146191## 🙌 Acknowledgements
147192
148193This project includes and re-exports [ ` http-status-toolkit ` ] ( https://www.npmjs.com/package/http-status-toolkit ) , also created by me.
194+
195+
196+ ## Contributions
197+ Feel free to suggest improvements or add new status codes by opening issues or pull requests on GitHub.
198+
199+
200+ ## Links
201+
202+ - ** GitHub:** [ Rashedin-063] ( https://github.com/dev-rashedin )
203+ - ** Portfolio:** [ rashedin.dev] ( https://www.rashedin.dev )
204+
205+ ---
206+
207+ Made with ❤️ by [ Rashedin Islam] ( https://www.rashedin.dev )
0 commit comments