init
This commit is contained in:
14
src/utils/ApiError.js
Normal file
14
src/utils/ApiError.js
Normal file
@@ -0,0 +1,14 @@
|
||||
class ApiError extends Error {
|
||||
constructor(statusCode, message, isOperational = true, stack = '') {
|
||||
super(message);
|
||||
this.statusCode = statusCode;
|
||||
this.isOperational = isOperational;
|
||||
if (stack) {
|
||||
this.stack = stack;
|
||||
} else {
|
||||
Error.captureStackTrace(this, this.constructor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ApiError;
|
||||
5
src/utils/catchAsync.js
Normal file
5
src/utils/catchAsync.js
Normal file
@@ -0,0 +1,5 @@
|
||||
const catchAsync = (fn) => (req, res, next) => {
|
||||
Promise.resolve(fn(req, res, next)).catch((err) => next(err));
|
||||
};
|
||||
|
||||
module.exports = catchAsync;
|
||||
17
src/utils/pick.js
Normal file
17
src/utils/pick.js
Normal file
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* Create an object composed of the picked object properties
|
||||
* @param {Object} object
|
||||
* @param {string[]} keys
|
||||
* @returns {Object}
|
||||
*/
|
||||
const pick = (object, keys) => {
|
||||
return keys.reduce((obj, key) => {
|
||||
if (object && Object.prototype.hasOwnProperty.call(object, key)) {
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
obj[key] = object[key];
|
||||
}
|
||||
return obj;
|
||||
}, {});
|
||||
};
|
||||
|
||||
module.exports = pick;
|
||||
Reference in New Issue
Block a user