|
@ -13,6 +13,7 @@ import { |
|
|
AuthenticationErrorReason, |
|
|
AuthenticationErrorReason, |
|
|
ProviderRequestClientError, |
|
|
ProviderRequestClientError, |
|
|
ProviderRequestNotFoundError, |
|
|
ProviderRequestNotFoundError, |
|
|
|
|
|
ProviderRequestRateLimitError, |
|
|
} from '../../errors'; |
|
|
} from '../../errors'; |
|
|
import { PagedResult, RepositoryVisibility } from '../../git/gitProvider'; |
|
|
import { PagedResult, RepositoryVisibility } from '../../git/gitProvider'; |
|
|
import { |
|
|
import { |
|
@ -1748,11 +1749,24 @@ export class GitHubApi implements Disposable { |
|
|
throw new ProviderRequestNotFoundError(ex); |
|
|
throw new ProviderRequestNotFoundError(ex); |
|
|
case 'FORBIDDEN': |
|
|
case 'FORBIDDEN': |
|
|
throw new AuthenticationError('github', AuthenticationErrorReason.Forbidden, ex); |
|
|
throw new AuthenticationError('github', AuthenticationErrorReason.Forbidden, ex); |
|
|
|
|
|
case 'RATE_LIMITED': { |
|
|
|
|
|
let resetAt: number | undefined; |
|
|
|
|
|
|
|
|
|
|
|
const reset = ex.headers?.['x-ratelimit-reset']; |
|
|
|
|
|
if (reset != null) { |
|
|
|
|
|
resetAt = parseInt(reset, 10); |
|
|
|
|
|
if (Number.isNaN(resetAt)) { |
|
|
|
|
|
resetAt = undefined; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
throw new ProviderRequestRateLimitError(ex, token, resetAt); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void window.showErrorMessage(`GitHub request failed: ${ex.errors?.[0]?.message ?? ex.message}`, 'OK'); |
|
|
void window.showErrorMessage(`GitHub request failed: ${ex.errors?.[0]?.message ?? ex.message}`, 'OK'); |
|
|
} else if (ex instanceof RequestError) { |
|
|
} else if (ex instanceof RequestError) { |
|
|
this.handleRequestError(ex); |
|
|
|
|
|
|
|
|
this.handleRequestError(ex, token); |
|
|
} else { |
|
|
} else { |
|
|
void window.showErrorMessage(`GitHub request failed: ${ex.message}`, 'OK'); |
|
|
void window.showErrorMessage(`GitHub request failed: ${ex.message}`, 'OK'); |
|
|
} |
|
|
} |
|
@ -1770,7 +1784,7 @@ export class GitHubApi implements Disposable { |
|
|
return (await this.octokit(token).request<R>(route, options)) as any; |
|
|
return (await this.octokit(token).request<R>(route, options)) as any; |
|
|
} catch (ex) { |
|
|
} catch (ex) { |
|
|
if (ex instanceof RequestError) { |
|
|
if (ex instanceof RequestError) { |
|
|
this.handleRequestError(ex); |
|
|
|
|
|
|
|
|
this.handleRequestError(ex, token); |
|
|
} else { |
|
|
} else { |
|
|
void window.showErrorMessage(`GitHub request failed: ${ex.message}`, 'OK'); |
|
|
void window.showErrorMessage(`GitHub request failed: ${ex.message}`, 'OK'); |
|
|
} |
|
|
} |
|
@ -1779,7 +1793,7 @@ export class GitHubApi implements Disposable { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private handleRequestError(ex: RequestError): void { |
|
|
|
|
|
|
|
|
private handleRequestError(ex: RequestError, token: string): void { |
|
|
switch (ex.status) { |
|
|
switch (ex.status) { |
|
|
case 404: // Not found
|
|
|
case 404: // Not found
|
|
|
case 410: // Gone
|
|
|
case 410: // Gone
|
|
@ -1789,6 +1803,19 @@ export class GitHubApi implements Disposable { |
|
|
case 401: // Unauthorized
|
|
|
case 401: // Unauthorized
|
|
|
throw new AuthenticationError('github', AuthenticationErrorReason.Unauthorized, ex); |
|
|
throw new AuthenticationError('github', AuthenticationErrorReason.Unauthorized, ex); |
|
|
case 403: // Forbidden
|
|
|
case 403: // Forbidden
|
|
|
|
|
|
if (ex.message.includes('rate limit exceeded')) { |
|
|
|
|
|
let resetAt: number | undefined; |
|
|
|
|
|
|
|
|
|
|
|
const reset = ex.response?.headers?.['x-ratelimit-reset']; |
|
|
|
|
|
if (reset != null) { |
|
|
|
|
|
resetAt = parseInt(reset, 10); |
|
|
|
|
|
if (Number.isNaN(resetAt)) { |
|
|
|
|
|
resetAt = undefined; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
throw new ProviderRequestRateLimitError(ex, token, resetAt); |
|
|
|
|
|
} |
|
|
throw new AuthenticationError('github', AuthenticationErrorReason.Forbidden, ex); |
|
|
throw new AuthenticationError('github', AuthenticationErrorReason.Forbidden, ex); |
|
|
case 500: // Internal Server Error
|
|
|
case 500: // Internal Server Error
|
|
|
if (ex.response != null) { |
|
|
if (ex.response != null) { |
|
|