From c51b142abde5af966e469b74031477fcbfa5af22 Mon Sep 17 00:00:00 2001 From: Nick Coutsos Date: Sun, 7 Nov 2021 22:25:15 -0500 Subject: Display load errors in UI --- application/components/github/api.js | 23 ++++---- application/components/github/invalid-repo.vue | 30 ++-------- application/components/github/picker.vue | 17 +++--- .../components/github/validation-errors.vue | 66 ++++++++++++++++++++++ 4 files changed, 94 insertions(+), 42 deletions(-) create mode 100644 application/components/github/validation-errors.vue (limited to 'application/components/github') diff --git a/application/components/github/api.js b/application/components/github/api.js index a7cbfbb..cce9aec 100644 --- a/application/components/github/api.js +++ b/application/components/github/api.js @@ -100,17 +100,20 @@ export class API extends EventEmitter { url.search = new URLSearchParams({ branch }).toString() } - const { status, data } = await this._request(url.toString()) - - if (status === 400) { - console.error('Failed to load keymap and layout from github') - return data - } + try { + const { data } = await this._request(url.toString()) + const defaultLayout = data.info.layouts.default || data.info.layouts[Object.keys(data.info.layouts)[0]] + return { + layout: defaultLayout.layout, + keymap: data.keymap + } + } catch (err) { + if (err.response?.status === 400) { + console.error('Failed to load keymap and layout from github', err.response.data) + this.emit('repo-validation-error', err.response.data) + } - const defaultLayout = data.info.layouts.default || data.info.layouts[Object.keys(data.info.layouts)[0]] - return { - layout: defaultLayout.layout, - keymap: data.keymap + throw err } } diff --git a/application/components/github/invalid-repo.vue b/application/components/github/invalid-repo.vue index eee706f..bbb4e3d 100644 --- a/application/components/github/invalid-repo.vue +++ b/application/components/github/invalid-repo.vue @@ -1,6 +1,6 @@ diff --git a/application/components/github/picker.vue b/application/components/github/picker.vue index 2e27bc7..43f70ae 100644 --- a/application/components/github/picker.vue +++ b/application/components/github/picker.vue @@ -30,8 +30,10 @@ /> - @@ -46,13 +48,14 @@ import map from 'lodash/map' import github from './api' import * as storage from './storage' import InvalidRepo from './invalid-repo.vue' +import ValidationErrors from './validation-errors.vue' import Loader from '../loader.vue' import Selector from '../selector.vue' import Spinner from '../spinner.vue' export default { name: 'GithubPicker', - components: { InvalidRepo, Loader, Selector, Spinner }, + components: { InvalidRepo, Loader, Selector, Spinner, ValidationErrors }, emits: ['select'], data() { return { @@ -68,6 +71,10 @@ export default { github.on('authentication-failed', () => { github.beginLoginFlow() }) + github.on('repo-validation-error', err => { + this.loadKeyboardError = err + this.loadingKeyboard = false + }) }, watch: { repo(value) { @@ -150,10 +157,6 @@ export default { const response = await github.fetchLayoutAndKeymap(repository, branch) this.loadingKeyboard = false - if (response.error) { - this.loadKeyboardError = response.error - return - } this.$emit('select', { github: { repository, branch }, ...response }) }, diff --git a/application/components/github/validation-errors.vue b/application/components/github/validation-errors.vue new file mode 100644 index 0000000..2b08e5a --- /dev/null +++ b/application/components/github/validation-errors.vue @@ -0,0 +1,66 @@ + + + + + -- cgit v1.2.3