From 197d0778d4b0ba02fada2bee6d16c2ab1dc77a8d Mon Sep 17 00:00:00 2001 From: EnixCoda Date: Wed, 19 Sep 2018 21:48:32 +0800 Subject: [PATCH] feat: raise GitHub helper errors --- src/utils/GitHubHelper.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/utils/GitHubHelper.js b/src/utils/GitHubHelper.js index 32605eb..76535c3 100644 --- a/src/utils/GitHubHelper.js +++ b/src/utils/GitHubHelper.js @@ -1,3 +1,4 @@ +import { raiseError } from '../analytics' export const NOT_FOUND = 'Repo Not Found' export const BAD_CREDENTIALS = 'Bad credentials' @@ -7,6 +8,7 @@ async function request(url, { accessToken } = {}) { headers.Authorization = `token ${accessToken}` } const res = await fetch(url, { headers }) + if (!res.ok) raiseError(new Error(`Got ${res.statusText} when requesting ${url}`)) if (res.status === 200) return res.json() // for private repo, GitHub api also responses with 404 when unauthorized if (res.status === 404) throw new Error(NOT_FOUND)