From 5e5545789fbfd2520fa682318d081f387f67fdda Mon Sep 17 00:00:00 2001 From: Leo Lamprecht Date: Sat, 26 Nov 2016 12:19:49 +0100 Subject: [PATCH] Handle potential error when converting res to JSON --- lib/github.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/github.js b/lib/github.js index f47d864..780c0a6 100644 --- a/lib/github.js +++ b/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 => {