Skip to content

Commit

Permalink
fix: Show error message when requesting non-existent repository. (#252)…
Browse files Browse the repository at this point in the history
… …

Instead of failing silently, show an error message when the workspace loading fails.
  • Loading branch information
Zoramite committed Nov 12, 2021
1 parent 841dd17 commit 15c1f30
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions src/ts/editor/ui/parts/onboarding/github.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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/';
Expand All @@ -33,6 +35,7 @@ export interface GitHubOnboardingPartConfig extends UiPartConfig {

export class GitHubOnboardingPart extends BasePart implements UiPartComponent {
config: GitHubOnboardingPartConfig;
error?: ApiError;
organizations?: Array<GitHubInstallationInfo>;
installation?: GitHubInstallationInfo;
/**
Expand Down Expand Up @@ -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();
}
}
Expand All @@ -137,15 +141,24 @@ export class GitHubOnboardingPart extends BasePart implements UiPartComponent {
this.loadOrganizations();
}

if (this.error) {
return;
}

this.api
.getWorkspaces(this.api.organization, this.api.project)
.then(workspaces => {
this.workspaces = workspaces;
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);
});
}

Expand Down Expand Up @@ -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(
{
Expand Down Expand Up @@ -468,6 +482,7 @@ export class GitHubOnboardingPart extends BasePart implements UiPartComponent {
);
this.api.project = repository;
this.listFilter = undefined;
this.error = undefined;
history.pushState(
{
Expand Down Expand Up @@ -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(
{
Expand Down Expand Up @@ -734,7 +750,8 @@ export class GitHubOnboardingPart extends BasePart implements UiPartComponent {
${useFilter ? this.templateFilter() : 'Workspace'}
</div>
</div>
${this.workspaces
${this.error ? templateApiError(this.error, {pad: true}) : ''}
${this.workspaces || this.error
? ''
: this.templateLoadingStatus(html`Finding
${this.api.organization}/${this.api.project} workspaces…`)}
Expand All @@ -751,6 +768,7 @@ export class GitHubOnboardingPart extends BasePart implements UiPartComponent {
})}
@click=${() => {
this.api.branch = workspace.name;
this.error = undefined;
history.pushState(
{
Expand Down

0 comments on commit 15c1f30

Please sign in to comment.