Skip to content

Commit 5cb9603

Browse files
committed
fix: update error handler to correctly log API Route errors and improve consistency for both API Routes and App Router.
1 parent bdd98b6 commit 5cb9603

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

CHANGELOG.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/), and this
1919
- Improved error handling for unsupported HTTP methods.
2020
- Expanded documentation in the README.
2121

22-
## [1.1.9] - 2024-10-30
22+
## [1.0.9] - 2024-10-30
2323
### Fixed
2424
- Enhanced the `errorHandler` function to support both API Routes and App Router in Next.js, allowing for flexible error handling across different route types.
25-
- Adjusted error response handling to ensure appropriate responses are returned based on the presence of `res` in the request.
25+
- Adjusted error response handling to ensure appropriate responses are returned based on the presence of `res` in the request.
26+
27+
## [1.0.10] - 2024-10-30
28+
### Fixed
29+
- Corrected log message for errors in API Route handling to reflect 'API Route Error:' instead of 'Route Error:' in the logger.
30+
- Ensured consistent error handling for both API Routes and App Router by refining the errorHandler implementation.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nextjs-centralized-error-handler",
3-
"version": "1.0.9",
3+
"version": "1.0.10",
44
"main": "src/index.js",
55
"scripts": {
66
"test": "jest",

src/errorHandler.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ function errorHandler(handler, options = {}) {
2525
}
2626
} catch (error) {
2727
// Log the error for monitoring and debugging
28-
logger('Route Error:', error);
28+
const logMessage = res && typeof res.status === 'function' ? 'API Route Error:' : 'Route Error:';
29+
logger(logMessage, error);
2930

3031
let statusCode = defaultStatusCode;
3132
let message = defaultMessage;

0 commit comments

Comments
 (0)