mirror of
https://github.com/System-End/github-readme-stats.git
synced 2026-04-19 15:28:25 +00:00
Gist card: handle not found error (#3100)
This commit is contained in:
parent
c3c5a0dd32
commit
93733caaa6
2 changed files with 19 additions and 0 deletions
|
|
@ -60,6 +60,7 @@ const fetchGist = async (id) => {
|
|||
if (!id) throw new MissingParamError(["id"], "/api/gist?id=GIST_ID");
|
||||
const res = await retryer(fetcher, { gistName: id });
|
||||
if (res.data.errors) throw new Error(res.data.errors[0].message);
|
||||
if (!res.data.data.viewer.gist) throw new Error("Gist not found");
|
||||
const data = res.data.data.viewer.gist;
|
||||
return {
|
||||
name: data.files[Object.keys(data.files)[0]].name,
|
||||
|
|
|
|||
|
|
@ -52,6 +52,14 @@ const gist_data = {
|
|||
},
|
||||
};
|
||||
|
||||
const gist_not_found_data = {
|
||||
data: {
|
||||
viewer: {
|
||||
gist: null,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const gist_errors_data = {
|
||||
errors: [
|
||||
{
|
||||
|
|
@ -83,6 +91,16 @@ describe("Test fetchGist", () => {
|
|||
});
|
||||
});
|
||||
|
||||
it("should throw correct error if gist not found", async () => {
|
||||
mock
|
||||
.onPost("https://api.github.com/graphql")
|
||||
.reply(200, gist_not_found_data);
|
||||
|
||||
await expect(fetchGist("bbfce31e0217a3689c8d961a356cb10d")).rejects.toThrow(
|
||||
"Gist not found",
|
||||
);
|
||||
});
|
||||
|
||||
it("should throw error if reaponse contains them", async () => {
|
||||
mock.onPost("https://api.github.com/graphql").reply(200, gist_errors_data);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue