fix: handle blocked projects

This commit is contained in:
Enix 2019-04-24 11:53:06 +08:00
parent a95d41fa5c
commit 2d5ad3aca4
2 changed files with 11 additions and 4 deletions

View file

@ -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<Props, ConnectorState> = dispatch => async () => {
const handleError: MethodCreator<Props, ConnectorState, [Error]> = 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 ||

View file

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