diff options
Diffstat (limited to 'application/github.js')
-rw-r--r-- | application/github.js | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/application/github.js b/application/github.js index 51dafea..08fd664 100644 --- a/application/github.js +++ b/application/github.js @@ -1,8 +1,8 @@ import * as config from './config' let token -let installation -let repositories +export let installation +export let repositories function request (...args) { return fetch(...args).then(res => { @@ -48,10 +48,17 @@ export function isGitHubAuthorized() { } export async function fetchLayoutAndKeymap() { - const data = await request( + const response = await request( `${config.apiBaseUrl}/github/keyboard-files/${encodeURIComponent(installation.id)}/${encodeURIComponent(repositories[0].full_name)}`, { headers: { Authorization: `Bearer ${localStorage.auth_token}`} } - ).then(res => res.json()) + ) + + if (response.status === 400) { + console.error('Failed to load keymap and layout from github') + return response.json() + } + + const data = await response.json() const defaultLayout = data.info.layouts.default || data.info.layouts[Object.keys(data.info.layouts)[0]] return { layout: defaultLayout.layout, |