aboutsummaryrefslogtreecommitdiffhomepage
path: root/api/services/github/files.js
diff options
context:
space:
mode:
Diffstat (limited to 'api/services/github/files.js')
-rw-r--r--api/services/github/files.js17
1 files changed, 14 insertions, 3 deletions
diff --git a/api/services/github/files.js b/api/services/github/files.js
index 5f5837f..40bcb41 100644
--- a/api/services/github/files.js
+++ b/api/services/github/files.js
@@ -4,12 +4,22 @@ const zmk = require('../zmk')
const MODE_FILE = '100644'
+class InvalidRepoError extends Error {}
+
async function fetchKeyboardFiles (installationId, repository) {
const { data: { token: installationToken } } = await auth.createInstallationToken(installationId)
- const { data: info } = await fetchFile(installationToken, repository, 'config/info.json', true)
- const { data: keymap } = await fetchFile(installationToken, repository, 'config/keymap.json', true)
+ try {
+ const { data: info } = await fetchFile(installationToken, repository, 'config/info.json', true)
+ const { data: keymap } = await fetchFile(installationToken, repository, 'config/keymap.json', true)
+
+ return { info, keymap }
+ } catch (err) {
+ if (err.response && err.response.status === 404) {
+ throw new InvalidRepoError()
+ }
- return { info, keymap }
+ throw err
+ }
}
function fetchFile (installationToken, repository, path, raw = false) {
@@ -76,6 +86,7 @@ async function commitChanges (installationId, repository, layout, keymap) {
}
module.exports = {
+ InvalidRepoError,
fetchKeyboardFiles,
commitChanges
}