Skip to content

Commit cc81d4c

Browse files
Remove eslint config airbnb base (updated 4 years ago), update eslint, update catchAsync export (#31)
1 parent c164e9f commit cc81d4c

File tree

3 files changed

+63
-95
lines changed

3 files changed

+63
-95
lines changed

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@
4646
"devDependencies": {
4747
"@eslint/js": "^9.27.0",
4848
"@types/jest": "^29.5.14",
49-
"eslint": "^8.54.0",
50-
"eslint-config-airbnb-base": "^15.0.0",
49+
"eslint": "^9.29.0",
5150
"eslint-config-prettier": "^10.1.5",
5251
"eslint-plugin-import": "^2.31.0",
5352
"globals": "^16.2.0",

pnpm-lock.yaml

Lines changed: 49 additions & 78 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/utils/catchAsync.js

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
1-
class ApiError extends Error {
2-
constructor(statusCode, message, isOperational = true, stack = '') {
3-
super(message);
1+
/**
2+
* Utility function to wrap async Express route handlers
3+
* Catches async errors and passes them to Express error handling middleware
4+
* @param {Function} fn - Async function to wrap
5+
* @returns {Function} Express middleware function
6+
*/
7+
function catchAsync(fn) {
8+
return (req, res, next) => {
9+
// Execute the async function and catch any errors
10+
Promise.resolve(fn(req, res, next)).catch(next);
11+
};
12+
}
413

5-
if (stack) {
6-
this.stack = stack;
7-
} else {
8-
Error.captureStackTrace(this, this.constructor);
9-
}
10-
11-
this.statusCode = statusCode;
12-
this.isOperational = isOperational;
13-
}
14-
}
15-
16-
module.exports = ApiError;
14+
module.exports = catchAsync;
1715

0 commit comments

Comments
 (0)