Skip to content

Commit 718b419

Browse files
committed
ansi color codes separated in utils folder and changelog updated
1 parent 8198595 commit 718b419

File tree

5 files changed

+49
-5
lines changed

5 files changed

+49
-5
lines changed

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,22 @@ This project adheres to [Semantic Versioning](https://semver.org) and follows [C
55

66
---
77

8+
## [1.1.0](https://github.com/dev-rashedin/express-error-toolkit/releases/tag/1.1.0) – 2025-07-18
9+
10+
### ✨ Improvements
11+
12+
- Enhanced `globalErrorHandler` with smarter defaults:
13+
- `showStack` and `logError` are now **enabled by default**, unless:
14+
- explicitly set to `false`, **or**
15+
- `NODE_ENV` is `'production'`
16+
- Added ANSI color formatting to make console errors more readable
17+
- Users can customize behavior via:
18+
- `.env` (`SHOW_STACK=false`, `LOG_ERROR=false`)
19+
- `setErrorOptions()` function in code
20+
- Included updated usage guide and console screenshot in README
21+
22+
---
23+
824
## [1.0.1](https://github.com/dev-rashedin/express-error-toolkit/releases/tag/1.0.1) – 2025-07-09
925

1026
### ✨ Improvements

assets/console-preview.png

58.4 KB
Loading

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "express-error-toolkit",
3-
"version": "1.0.1",
3+
"version": "1.1.0",
44
"description": "A lightweight and developer-friendly toolkit for robust error handling in Express.js applications.\nIncludes ready-to-use custom error classes, an async route error handler wrapper, a global error handler middleware, and a convenient 'not found' route handler.\nDesigned to simplify error management, reduce boilerplate, and improve app reliability — all with TypeScript support and easy integration.",
55
"author": "Rashedin Islam <[email protected]>",
66
"license": "MIT",

src/global-error-handler.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ import { Request, Response, NextFunction } from 'express';
22
import { StatusCodes, getStatusMessage } from 'http-status-toolkit';
33
import { isCustomAPIError } from './checking-custom-api-error';
44
import { CustomAPIError } from './error';
5-
6-
7-
5+
import { boldRed, red, boldYellow, yellow, boldGreen, green } from './utils/console-colors';
86

97
// Internal config object (optional override)
108
let errorOptions = {
@@ -22,7 +20,6 @@ export function setErrorOptions(
2220
};
2321
}
2422

25-
2623
export interface ErrorResponse {
2724
success: false;
2825
message: string;

src/utils/console-colors.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
const colors = {
2+
reset: '\x1b[0m',
3+
bold: '\x1b[1m',
4+
red: '\x1b[31m',
5+
yellow: '\x1b[33m',
6+
green: '\x1b[32m',
7+
};
8+
9+
export function boldRed(text: string) : string {
10+
return `${colors.bold}${colors.red}${text}${colors.reset}`;
11+
}
12+
13+
export function red(text: string) : string {
14+
return `${colors.red}${text}${colors.reset}`;
15+
}
16+
17+
export function boldYellow(text: string) : string {
18+
return `${colors.bold}${colors.yellow}${text}${colors.reset}`;
19+
}
20+
21+
export function yellow(text: string) : string {
22+
return `${colors.yellow}${text}${colors.reset}`;
23+
}
24+
25+
export function boldGreen(text: string) : string {
26+
return `${colors.bold}${colors.green}${text}${colors.reset}`;
27+
}
28+
29+
export function green(text: string) : string {
30+
return `${colors.green}${text}${colors.reset}`;
31+
}

0 commit comments

Comments
 (0)