diff --git a/src/driver/core/SideBar.ts b/src/driver/core/SideBar.ts index 725f293..0be0ef5 100644 --- a/src/driver/core/SideBar.ts +++ b/src/driver/core/SideBar.ts @@ -6,6 +6,7 @@ import GitHubHelper, { EMPTY_PROJECT, MetaData, TreeData, + BLOCKED_PROJECT, } from 'utils/GitHubHelper' import configHelper from 'utils/configHelper' import URLHelper from 'utils/URLHelper' @@ -142,6 +143,8 @@ const init: MethodCreator = dispatch => async () => { const handleError: MethodCreator = dispatch => async err => { if (err.message === EMPTY_PROJECT) { dispatch.call(setError, 'This project seems to be empty.') + } else if (err.message === BLOCKED_PROJECT) { + dispatch.call(setError, 'This project is blocked.') } else if ( err.message === NOT_FOUND || err.message === BAD_CREDENTIALS || diff --git a/src/utils/GitHubHelper.ts b/src/utils/GitHubHelper.ts index 256f14c..761226f 100644 --- a/src/utils/GitHubHelper.ts +++ b/src/utils/GitHubHelper.ts @@ -3,19 +3,22 @@ export const NOT_FOUND = 'Repo Not Found' export const BAD_CREDENTIALS = 'Bad credentials' export const API_RATE_LIMIT = `API rate limit` export const EMPTY_PROJECT = `Empty project` +export const BLOCKED_PROJECT = `Blocked project` -function apiRateLimitExceeded(content: any) { - // it's ok +function apiRateLimitExceeded(content: any /* examined any */) { return ( content && content['documentation_url'] === 'https://developer.github.com/v3/#rate-limiting' ) } -function isEmptyProject(content: any) { - // it's ok +function isEmptyProject(content: any /* examined any */) { return content && content['message'] === 'Git Repository is empty.' } +function isBlockedProject(content: any /* examined any */) { + return content && content['message'] === "Repository access blocked" +} + type Options = { accessToken?: string } @@ -40,6 +43,7 @@ async function request(url: string, { accessToken }: Options = {}) { const content = await res.json() if (apiRateLimitExceeded(content)) throw new Error(API_RATE_LIMIT) if (isEmptyProject(content)) throw new Error(EMPTY_PROJECT) + if (isBlockedProject(content)) throw new Error(BLOCKED_PROJECT) // Unknown type of error, report it! raiseError(new Error(`Got ${res.statusText} when requesting ${url}`)) throw new Error(content && content.message)