From 15c1f30568d49130b801f2f4db76265f6bfb9aa9 Mon Sep 17 00:00:00 2001 From: Randy Merrill Date: Fri, 12 Nov 2021 15:10:50 -0700 Subject: [PATCH] =?UTF-8?q?fix:=20Show=20error=20message=20when=20requesti?= =?UTF-8?q?ng=20non-existent=20repository.=20(#252)=20=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of failing silently, show an error message when the workspace loading fails. --- src/ts/editor/ui/parts/onboarding/github.ts | 26 +++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/ts/editor/ui/parts/onboarding/github.ts b/src/ts/editor/ui/parts/onboarding/github.ts index 1b377773..54a60beb 100644 --- a/src/ts/editor/ui/parts/onboarding/github.ts +++ b/src/ts/editor/ui/parts/onboarding/github.ts @@ -1,10 +1,11 @@ -import {BasePart, UiPartComponent, UiPartConfig} from '..'; import { + ApiError, GitHubInstallationInfo, GitHubOrgInstallationInfo, UserData, WorkspaceData, } from '../../../api'; +import {BasePart, UiPartComponent, UiPartConfig} from '..'; import {TemplateResult, classMap, html, repeat} from '@blinkk/selective-edit'; import { handleKeyboardNav, @@ -18,6 +19,7 @@ import {GitHubApi} from '../../../../server/gh/githubApi'; import {OnboardingBreadcrumbs} from '../onboarding'; import TimeAgo from 'javascript-time-ago'; import {githubIcon} from '../../icons'; +import {templateApiError} from '../../error'; const APP_URL = 'https://github.com/apps/editor-dev'; const BASE_URL = '/gh/'; @@ -33,6 +35,7 @@ export interface GitHubOnboardingPartConfig extends UiPartConfig { export class GitHubOnboardingPart extends BasePart implements UiPartComponent { config: GitHubOnboardingPartConfig; + error?: ApiError; organizations?: Array; installation?: GitHubInstallationInfo; /** @@ -127,6 +130,7 @@ export class GitHubOnboardingPart extends BasePart implements UiPartComponent { this.api.organization = evt.state.organization || undefined; this.api.project = evt.state.repository || undefined; this.api.branch = evt.state.branch || undefined; + this.error = undefined; this.config.state.checkOnboarding(); } } @@ -137,6 +141,10 @@ export class GitHubOnboardingPart extends BasePart implements UiPartComponent { this.loadOrganizations(); } + if (this.error) { + return; + } + this.api .getWorkspaces(this.api.organization, this.api.project) .then(workspaces => { @@ -144,8 +152,13 @@ export class GitHubOnboardingPart extends BasePart implements UiPartComponent { this.workspacesId = this.api.project; this.render(); }) - .catch(() => { - console.error('Unable to retrieve the list of branches.'); + .catch(err => { + err.json().then((json: any) => { + this.error = json as ApiError; + this.render(); + }); + + console.error('Unable to retrieve the list of workspaces.', err); }); } @@ -371,6 +384,7 @@ export class GitHubOnboardingPart extends BasePart implements UiPartComponent { this.api.organization = org.org; this.installation = org; this.listFilter = undefined; + this.error = undefined; history.pushState( { @@ -468,6 +482,7 @@ export class GitHubOnboardingPart extends BasePart implements UiPartComponent { ); this.api.project = repository; this.listFilter = undefined; + this.error = undefined; history.pushState( { @@ -584,6 +599,7 @@ export class GitHubOnboardingPart extends BasePart implements UiPartComponent { const handleClick = () => { this.api.project = repo.repo; this.listFilter = undefined; + this.error = undefined; history.pushState( { @@ -734,7 +750,8 @@ export class GitHubOnboardingPart extends BasePart implements UiPartComponent { ${useFilter ? this.templateFilter() : 'Workspace'} - ${this.workspaces + ${this.error ? templateApiError(this.error, {pad: true}) : ''} + ${this.workspaces || this.error ? '' : this.templateLoadingStatus(html`Finding ${this.api.organization}/${this.api.project} workspaces…`)} @@ -751,6 +768,7 @@ export class GitHubOnboardingPart extends BasePart implements UiPartComponent { })} @click=${() => { this.api.branch = workspace.name; + this.error = undefined; history.pushState( {