Skip to content

Commit 8198595

Browse files
committed
read me file updated
1 parent 3ef4317 commit 8198595

File tree

3 files changed

+28
-34
lines changed

3 files changed

+28
-34
lines changed

README.md

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,30 @@ import { globalErrorHandler } from 'express-error-toolkit';
126126
app.use(globalErrorHandler);
127127
```
128128

129-
By default, it includes stack trace and logs the error in development (`NODE_ENV=development`).
129+
By default, the handler includes the stack trace and logs the error in development.
130+
In production (`NODE_ENV=production`), both are automatically suppressed for safety.
130131

131132
---
132133

133-
### 5. **Set Options Globally (Optional)**
134+
### 5. 🖍️ Readable Console Logs with ANSI Colors
135+
136+
To enhance developer experience during debugging, this toolkit uses **ANSI escape codes** to style console logs — **no external dependencies** like `chalk`.
137+
138+
Each part of the error log is color-coded using a traffic light scheme:
139+
140+
- 🔴 **Error Message** – Red
141+
- 🟡 **Error Details** – Yellow
142+
- 🟢 **Stack Trace** – Green
143+
144+
> Here's an example of how your console might look in development:
145+
146+
![Colored error output preview](./assets/console-preview.png)
147+
148+
If needed, you can disable this output using either `.env` or `setErrorOptions()`:
149+
150+
---
151+
152+
### 6. **Set Options Globally (Optional)**
134153

135154
You can configure the error handling behavior (e.g., hide stack traces and disable console logging even in development) using either:
136155

@@ -154,7 +173,7 @@ This overrides the default behavior (based on `NODE_ENV` or `.env` file).
154173

155174
---
156175

157-
### 6. **httpError()**: Create generic custom errors
176+
### 7. **httpError()**: Create generic custom errors
158177

159178
```ts
160179
import { httpError } from 'express-error-toolkit';
@@ -165,26 +184,27 @@ throw httpError('Something custom', 418);
165184
You can also pass optional `errorDetails` as a string, object, or leave it out:
166185

167186
```ts
168-
throw new BadRequestError('Invalid data', { field: 'email' });
169-
throw new BadRequestError('Invalid input', 'Missing required field');
170-
throw new BadRequestError('Generic client error');
187+
throw httpError('Expectation failed', 417, { reason: 'The server could not meet the Expect header requirements' });
188+
throw httpError('Failed Dependency', 424, 'This request relies on a previous request that failed' );
189+
throw httpError('Unavailable for legal reason', 451);
171190
```
172191

173192
---
174193

175-
### 7. **isCustomAPIError()**: Type guard for checking error type
194+
### 8. **isCustomAPIError()**: Type guard for checking error type
176195

177196
```ts
178197
import { isCustomAPIError } from 'express-error-toolkit';
179198

180199
if (isCustomAPIError(err)) {
181200
console.log(err.statusCode, err.message);
201+
// your rest of the code
182202
}
183203
```
184204

185205
---
186206

187-
### 8. **Bonus**: Use status codes directly (re-exported from http-status-toolkit)
207+
### 9. **Bonus**: Use status codes directly (re-exported from http-status-toolkit)
188208

189209
```ts
190210
import { StatusCodes, getStatusMessage } from 'express-error-toolkit';

assets/console-preview.png

91.7 KB
Loading

src/global-error-handler.ts

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,8 @@ import { StatusCodes, getStatusMessage } from 'http-status-toolkit';
33
import { isCustomAPIError } from './checking-custom-api-error';
44
import { CustomAPIError } from './error';
55

6-
const colors = {
7-
reset: '\x1b[0m',
8-
bold: '\x1b[1m',
9-
red: '\x1b[31m',
10-
yellow: '\x1b[33m',
11-
green: '\x1b[32m',
12-
};
13-
14-
function boldRed(text: string) {
15-
return `${colors.bold}${colors.red}${text}${colors.reset}`;
16-
}
17-
function red(text: string) {
18-
return `${colors.red}${text}${colors.reset}`;
19-
}
206

21-
function boldYellow(text: string) {
22-
return `${colors.bold}${colors.yellow}${text}${colors.reset}`;
23-
}
24-
function yellow(text: string) {
25-
return `${colors.yellow}${text}${colors.reset}`;
26-
}
277

28-
function boldGreen(text: string) {
29-
return `${colors.bold}${colors.green}${text}${colors.reset}`;
30-
}
31-
function green(text: string) {
32-
return `${colors.green}${text}${colors.reset}`;
33-
}
348

359
// Internal config object (optional override)
3610
let errorOptions = {

0 commit comments

Comments
 (0)