Skip to content

Commit

Permalink
refactor(stats card fetcher): improve could not fetch total commits e…
Browse files Browse the repository at this point in the history
…rror message (#3255)
  • Loading branch information
qwerty541 authored Sep 21, 2023
1 parent 12f84f8 commit 65c3300
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/fetchers/stats-fetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,10 @@ const totalCommitsFetcher = async (username) => {

const totalCount = res.data.total_count;
if (!totalCount || isNaN(totalCount)) {
throw new Error("Could not fetch total commits.");
throw new CustomError(
"Could not fetch total commits.",
CustomError.GRAPHQL_ERROR,
);
}
return totalCount;
};
Expand Down
18 changes: 18 additions & 0 deletions tests/api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,4 +304,22 @@ describe("Test /api/", () => {
renderError("Something went wrong", "Language not found"),
);
});

it("should render error card when include_all_commits true and upstream API fails", async () => {
mock
.onGet("https://api.github.com/search/commits?q=author:anuraghazra")
.reply(200, { error: "Some test error message" });

const { req, res } = faker(
{ username: "anuraghazra", include_all_commits: true },
data_stats,
);

await api(req, res);

expect(res.setHeader).toBeCalledWith("Content-Type", "image/svg+xml");
expect(res.send).toBeCalledWith(
renderError("Could not fetch total commits.", "Please try again later"),
);
});
});

0 comments on commit 65c3300

Please sign in to comment.