Skip to content

Commit

Permalink
fix: catched all errors (#384)
Browse files Browse the repository at this point in the history
  • Loading branch information
anuraghazra authored Aug 13, 2020
1 parent ec246d2 commit 056aaaf
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 74 deletions.
50 changes: 25 additions & 25 deletions api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,32 +37,32 @@ module.exports = async (req, res) => {
parseBoolean(count_private),
parseBoolean(include_all_commits)
);
} catch (err) {
return res.send(renderError(err.message, err.secondaryMessage));
}

const cacheSeconds = clampValue(
parseInt(cache_seconds || CONSTANTS.TWO_HOURS, 10),
CONSTANTS.TWO_HOURS,
CONSTANTS.ONE_DAY
);
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.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,
})
);
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) {
return res.send(renderError(err.message, err.secondaryMessage));
}
};
54 changes: 27 additions & 27 deletions api/pin.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,39 +27,39 @@ module.exports = async (req, res) => {

try {
repoData = await fetchRepo(username, repo);
} catch (err) {
return res.send(renderError(err.message, err.secondaryMessage));
}

let cacheSeconds = clampValue(
parseInt(cache_seconds || CONSTANTS.TWO_HOURS, 10),
CONSTANTS.TWO_HOURS,
CONSTANTS.ONE_DAY
);
let cacheSeconds = clampValue(
parseInt(cache_seconds || CONSTANTS.TWO_HOURS, 10),
CONSTANTS.TWO_HOURS,
CONSTANTS.ONE_DAY
);

/*
/*
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
so we can just make the cache longer, since there is no need to frequent updates
*/
const stars = repoData.stargazers.totalCount;
const forks = repoData.forkCount;
const isBothOver1K = stars > 1000 && forks > 1000;
const isBothUnder1 = stars < 1 && forks < 1;
if (!cache_seconds && (isBothOver1K || isBothUnder1)) {
cacheSeconds = CONSTANTS.FOUR_HOURS;
}
const stars = repoData.stargazers.totalCount;
const forks = repoData.forkCount;
const isBothOver1K = stars > 1000 && forks > 1000;
const isBothUnder1 = stars < 1 && forks < 1;
if (!cache_seconds && (isBothOver1K || isBothUnder1)) {
cacheSeconds = CONSTANTS.FOUR_HOURS;
}

res.setHeader("Cache-Control", `public, max-age=${cacheSeconds}`);
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),
})
);
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));
}
};
44 changes: 22 additions & 22 deletions api/top-langs.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,29 +29,29 @@ module.exports = async (req, res) => {

try {
topLangs = await fetchTopLanguages(username);
} catch (err) {
return res.send(renderError(err.message, err.secondaryMessage));
}

const cacheSeconds = clampValue(
parseInt(cache_seconds || CONSTANTS.TWO_HOURS, 10),
CONSTANTS.TWO_HOURS,
CONSTANTS.ONE_DAY
);
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.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,
})
);
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) {
return res.send(renderError(err.message, err.secondaryMessage));
}
};

0 comments on commit 056aaaf

Please sign in to comment.