|
3 | 3 | [](https://www.npmjs.com/package/express-error-toolkit) |
4 | 4 |  |
5 | 5 | [](https://github.com/dev-rashedin/express-error-toolkit/blob/main/LICENSE) |
6 | | -[](https://www.npmjs.com/package/express-error-toolkit) |
7 | 6 | [](https://github.com/dev-rashedin/express-error-toolkit/stargazers) |
8 | 7 |  |
9 | 8 |  |
@@ -36,12 +35,30 @@ It provides: |
36 | 35 |
|
37 | 36 | --- |
38 | 37 |
|
39 | | -## 📦 Installation |
| 38 | +# 🚀 Installation Guide |
| 39 | + |
| 40 | +You can install **express-error-toolkit** using your favorite package manager. |
| 41 | + |
| 42 | +## Using npm |
40 | 43 |
|
41 | 44 | ```bash |
42 | 45 | npm install express-error-toolkit |
43 | 46 | ``` |
44 | 47 |
|
| 48 | +## Using yarn |
| 49 | + |
| 50 | +```bash |
| 51 | +yarn add express-error-toolkit |
| 52 | +``` |
| 53 | + |
| 54 | +## Using pnpm |
| 55 | + |
| 56 | +```bash |
| 57 | +pnpm add express-error-toolkit |
| 58 | +``` |
| 59 | + |
| 60 | +> ℹ️ Make sure you have `express` installed in your project, as this toolkit is built specifically to enhance Express.js error handling. |
| 61 | +
|
45 | 62 | --- |
46 | 63 |
|
47 | 64 | ## 📁 Usage |
@@ -75,7 +92,15 @@ app.get('/test', (req, res) => { |
75 | 92 | }); |
76 | 93 | ``` |
77 | 94 |
|
78 | | -Each custom error sets the correct `statusCode` and `name` automatically. |
| 95 | +Each custom error automatically sets the correct `statusCode` and `name`. |
| 96 | + |
| 97 | +You can also pass optional `errorDetails` as a string, object, or leave it out: |
| 98 | + |
| 99 | +```ts |
| 100 | +throw new BadRequestError('Invalid data', { field: 'email' }); |
| 101 | +throw new BadRequestError('Invalid input', 'Missing required field'); |
| 102 | +throw new BadRequestError('Generic client error'); |
| 103 | +``` |
79 | 104 |
|
80 | 105 | --- |
81 | 106 |
|
@@ -111,6 +136,14 @@ import { httpError } from 'express-error-toolkit'; |
111 | 136 | throw httpError('Something custom', 418); |
112 | 137 | ``` |
113 | 138 |
|
| 139 | +You can also pass optional `errorDetails` as a string, object, or leave it out: |
| 140 | + |
| 141 | +```ts |
| 142 | +throw new BadRequestError('Invalid data', { field: 'email' }); |
| 143 | +throw new BadRequestError('Invalid input', 'Missing required field'); |
| 144 | +throw new BadRequestError('Generic client error'); |
| 145 | +``` |
| 146 | + |
114 | 147 | --- |
115 | 148 |
|
116 | 149 | ### 6. **isCustomAPIError()**: Type guard for checking error type |
|
0 commit comments