initial commit

This commit is contained in:
zyachel
2022-03-19 17:22:07 +05:30
commit d660f9ea58
55 changed files with 5999 additions and 0 deletions

8
utils/axiosInstance.js Normal file
View File

@ -0,0 +1,8 @@
const axios = require('axios').default;
const axiosInstance = axios.create({
baseURL: 'https://www.imdb.com/',
timeout: 500000,
});
module.exports = axiosInstance;

32
utils/errorUtils.js Normal file
View File

@ -0,0 +1,32 @@
// class that'll make all errors in the app categorisable into operational and non-operational errors
/**
* similar to Error class, but much cooler for this app
*/
exports.AppError = class extends Error {
/**
*
* @param {string} message message that'll show up on err.message
* @param {number} statusCode err status code
*/
constructor(message, statusCode) {
super(message);
this.statusCode = statusCode || 500;
this.status = `${statusCode}`.startsWith('4') ? 'fail' : 'error';
this.isOperational = true;
// Error.captureStackTrace(this, this.constructor);
}
};
// alternative for the ugly trycatch blocks
/**
* wrapper for async functions in the controller
* @param {function} controller async function whose errors are to be caught
* @returns a function similar to express's middleware which executes all the logic of the passed function
*/
exports.catchErrors = function (controller) {
return (req, res, next) => {
controller(req, res, next).catch(err => next(err));
};
};