Reduce cyclomatic complexity

pull/59/head
MillenniumEarl 2020-12-12 13:41:39 +01:00
parent 0db26c6e26
commit 6f4b3a4e44
1 changed files with 8 additions and 3 deletions

View File

@ -39,18 +39,23 @@ const commonConfig = {
* @returns {Promise<String>} HTML code or `null` if an error arise * @returns {Promise<String>} HTML code or `null` if an error arise
*/ */
module.exports.fetchHTML = async function (url) { module.exports.fetchHTML = async function (url) {
// Local variables
let returnValue = null;
// Fetch the response of the platform // Fetch the response of the platform
const response = await exports.fetchGETResponse(url); const response = await exports.fetchGETResponse(url);
// Manage response
if (!response) { if (!response) {
shared.logger.warn(`Unable to fetch HTML for ${url}`); shared.logger.warn(`Unable to fetch HTML for ${url}`);
return null;
} }
else if (!response.headers["content-type"].includes("text/html")) { else if (!response.headers["content-type"].includes("text/html")) {
// The response is not a HTML page // The response is not a HTML page
shared.logger.warn(`The ${url} returned a ${response.headers["content-type"]} response`); shared.logger.warn(`The ${url} returned a ${response.headers["content-type"]} response`);
return null;
} }
return response.data;
returnValue = response.data;
return returnValue;
}; };
/** /**