From 5db3af902414c7f3f0ef6d7797eb13c9ae7a3b2b Mon Sep 17 00:00:00 2001 From: Alexandr Garbuzov Date: Sun, 20 Aug 2023 10:58:16 +0300 Subject: [PATCH] Gist card: handle not found error (#3100) --- src/fetchers/gist-fetcher.js | 1 + tests/fetchGist.test.js | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/fetchers/gist-fetcher.js b/src/fetchers/gist-fetcher.js index 8e1eb75b2a86e..9ede43fda18fc 100644 --- a/src/fetchers/gist-fetcher.js +++ b/src/fetchers/gist-fetcher.js @@ -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, diff --git a/tests/fetchGist.test.js b/tests/fetchGist.test.js index ad52966f269c4..13c29a8d2fc39 100644 --- a/tests/fetchGist.test.js +++ b/tests/fetchGist.test.js @@ -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);