Gist card: handle not found error (#3100)

This commit is contained in:
Alexandr Garbuzov 2023-08-20 10:58:16 +03:00 committed by GitHub
parent c3c5a0dd32
commit 93733caaa6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 0 deletions

View file

@ -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,

View file

@ -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);