Browse Source

Handle potential error when converting res to JSON

master
Leo Lamprecht 8 years ago
parent
commit
5e5545789f
No known key found for this signature in database GPG Key ID: B08517883D5E0E10
  1. 9
      lib/github.js

9
lib/github.js

@ -12,22 +12,23 @@ import {error} from './error'
const exists = async repoPath => { const exists = async repoPath => {
const apiURL = `https://api.github.com/repos/${repoPath}` const apiURL = `https://api.github.com/repos/${repoPath}`
let request let request
let response
try { try {
request = await fetch(apiURL) request = await fetch(apiURL)
response = await request.json()
} catch (err) { } catch (err) {
error(`Not able to check if repo exists - ${err.message}`) error(`Not able to check if repo exists - ${err.message}`)
return false return false
} }
const res = await request.json() if (!response.name) {
if (!res.name) {
return false return false
} }
return res return response
} }
const downloadRepo = async repoPath => { const downloadRepo = async repoPath => {

Loading…
Cancel
Save