fix: catched all errors (#384)

This commit is contained in:
Anurag Hazra 2020-08-13 21:18:26 +05:30 committed by GitHub
parent ec246d27ab
commit 056aaaf189
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 75 additions and 75 deletions

View File

@ -37,32 +37,32 @@ module.exports = async (req, res) => {
parseBoolean(count_private), parseBoolean(count_private),
parseBoolean(include_all_commits) parseBoolean(include_all_commits)
); );
const cacheSeconds = clampValue(
parseInt(cache_seconds || CONSTANTS.TWO_HOURS, 10),
CONSTANTS.TWO_HOURS,
CONSTANTS.ONE_DAY
);
res.setHeader("Cache-Control", `public, max-age=${cacheSeconds}`);
return res.send(
renderStatsCard(stats, {
hide: parseArray(hide),
show_icons: parseBoolean(show_icons),
hide_title: parseBoolean(hide_title),
hide_border: parseBoolean(hide_border),
hide_rank: parseBoolean(hide_rank),
include_all_commits: parseBoolean(include_all_commits),
line_height,
title_color,
icon_color,
text_color,
bg_color,
theme,
})
);
} catch (err) { } catch (err) {
return res.send(renderError(err.message, err.secondaryMessage)); return res.send(renderError(err.message, err.secondaryMessage));
} }
const cacheSeconds = clampValue(
parseInt(cache_seconds || CONSTANTS.TWO_HOURS, 10),
CONSTANTS.TWO_HOURS,
CONSTANTS.ONE_DAY
);
res.setHeader("Cache-Control", `public, max-age=${cacheSeconds}`);
res.send(
renderStatsCard(stats, {
hide: parseArray(hide),
show_icons: parseBoolean(show_icons),
hide_title: parseBoolean(hide_title),
hide_border: parseBoolean(hide_border),
hide_rank: parseBoolean(hide_rank),
include_all_commits: parseBoolean(include_all_commits),
line_height,
title_color,
icon_color,
text_color,
bg_color,
theme,
})
);
}; };

View File

@ -27,39 +27,39 @@ module.exports = async (req, res) => {
try { try {
repoData = await fetchRepo(username, repo); repoData = await fetchRepo(username, repo);
} catch (err) {
return res.send(renderError(err.message, err.secondaryMessage));
}
let cacheSeconds = clampValue( let cacheSeconds = clampValue(
parseInt(cache_seconds || CONSTANTS.TWO_HOURS, 10), parseInt(cache_seconds || CONSTANTS.TWO_HOURS, 10),
CONSTANTS.TWO_HOURS, CONSTANTS.TWO_HOURS,
CONSTANTS.ONE_DAY CONSTANTS.ONE_DAY
); );
/* /*
if star count & fork count is over 1k then we are kFormating the text if star count & fork count is over 1k then we are kFormating the text
and if both are zero we are not showing the stats and if both are zero we are not showing the stats
so we can just make the cache longer, since there is no need to frequent updates so we can just make the cache longer, since there is no need to frequent updates
*/ */
const stars = repoData.stargazers.totalCount; const stars = repoData.stargazers.totalCount;
const forks = repoData.forkCount; const forks = repoData.forkCount;
const isBothOver1K = stars > 1000 && forks > 1000; const isBothOver1K = stars > 1000 && forks > 1000;
const isBothUnder1 = stars < 1 && forks < 1; const isBothUnder1 = stars < 1 && forks < 1;
if (!cache_seconds && (isBothOver1K || isBothUnder1)) { if (!cache_seconds && (isBothOver1K || isBothUnder1)) {
cacheSeconds = CONSTANTS.FOUR_HOURS; cacheSeconds = CONSTANTS.FOUR_HOURS;
}
res.setHeader("Cache-Control", `public, max-age=${cacheSeconds}`);
return res.send(
renderRepoCard(repoData, {
title_color,
icon_color,
text_color,
bg_color,
theme,
show_owner: parseBoolean(show_owner),
})
);
} catch (err) {
return res.send(renderError(err.message, err.secondaryMessage));
} }
res.setHeader("Cache-Control", `public, max-age=${cacheSeconds}`);
res.send(
renderRepoCard(repoData, {
title_color,
icon_color,
text_color,
bg_color,
theme,
show_owner: parseBoolean(show_owner),
})
);
}; };

View File

@ -29,29 +29,29 @@ module.exports = async (req, res) => {
try { try {
topLangs = await fetchTopLanguages(username); topLangs = await fetchTopLanguages(username);
const cacheSeconds = clampValue(
parseInt(cache_seconds || CONSTANTS.TWO_HOURS, 10),
CONSTANTS.TWO_HOURS,
CONSTANTS.ONE_DAY
);
res.setHeader("Cache-Control", `public, max-age=${cacheSeconds}`);
return res.send(
renderTopLanguages(topLangs, {
hide_title: parseBoolean(hide_title),
hide_border: parseBoolean(hide_border),
card_width: parseInt(card_width, 10),
hide: parseArray(hide),
title_color,
text_color,
bg_color,
theme,
layout,
})
);
} catch (err) { } catch (err) {
return res.send(renderError(err.message, err.secondaryMessage)); return res.send(renderError(err.message, err.secondaryMessage));
} }
const cacheSeconds = clampValue(
parseInt(cache_seconds || CONSTANTS.TWO_HOURS, 10),
CONSTANTS.TWO_HOURS,
CONSTANTS.ONE_DAY
);
res.setHeader("Cache-Control", `public, max-age=${cacheSeconds}`);
res.send(
renderTopLanguages(topLangs, {
hide_title: parseBoolean(hide_title),
hide_border: parseBoolean(hide_border),
card_width: parseInt(card_width, 10),
hide: parseArray(hide),
title_color,
text_color,
bg_color,
theme,
layout,
})
);
}; };