Browse Source
Handle potential error when converting res to JSON
master
Leo Lamprecht
8 years ago
No known key found for this signature in database
GPG Key ID: B08517883D5E0E10
1 changed files with
5 additions and
4 deletions
-
lib/github.js
|
|
@ -12,22 +12,23 @@ import {error} from './error' |
|
|
|
|
|
|
|
const exists = async repoPath => { |
|
|
|
const apiURL = `https://api.github.com/repos/${repoPath}` |
|
|
|
|
|
|
|
let request |
|
|
|
let response |
|
|
|
|
|
|
|
try { |
|
|
|
request = await fetch(apiURL) |
|
|
|
response = await request.json() |
|
|
|
} catch (err) { |
|
|
|
error(`Not able to check if repo exists - ${err.message}`) |
|
|
|
return false |
|
|
|
} |
|
|
|
|
|
|
|
const res = await request.json() |
|
|
|
|
|
|
|
if (!res.name) { |
|
|
|
if (!response.name) { |
|
|
|
return false |
|
|
|
} |
|
|
|
|
|
|
|
return res |
|
|
|
return response |
|
|
|
} |
|
|
|
|
|
|
|
const downloadRepo = async repoPath => { |
|
|
|