Skip to content

Commit

Permalink
Gist card: handle not found error (#3100)
Browse files Browse the repository at this point in the history
  • Loading branch information
qwerty541 authored Aug 20, 2023
1 parent c3c5a0d commit 93733ca
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/fetchers/gist-fetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
18 changes: 18 additions & 0 deletions tests/fetchGist.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ const gist_data = {
},
};

const gist_not_found_data = {
data: {
viewer: {
gist: null,
},
},
};

const gist_errors_data = {
errors: [
{
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 93733ca

Please sign in to comment.