From 2a58992eda2f13ec19822293b9dc35945750613d Mon Sep 17 00:00:00 2001 From: Caleb Date: Fri, 20 Apr 2018 10:23:36 -0600 Subject: [PATCH] Prevent login if Git Gateway is disabled. --- src/backends/git-gateway/API.js | 15 ++++++++++----- src/backends/github/API.js | 6 +++++- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/backends/git-gateway/API.js b/src/backends/git-gateway/API.js index 91221f03a71f..332c7ced6bab 100644 --- a/src/backends/git-gateway/API.js +++ b/src/backends/git-gateway/API.js @@ -16,12 +16,14 @@ export default class API extends GithubAPI { .catch(error => { if (error.status === 401) { if (error.message === "Bad credentials") { - throw new Error("Git Gateway Error: Please ask your site administrator to reissue the Git Gateway token."); + throw new APIError("Git Gateway Error: Please ask your site administrator to reissue the Git Gateway token.", error.status, 'Git Gateway'); } else { return false; } + } else if (error.status === 404 && (error.message === undefined || error.message === "Unable to locate site configuration")) { + throw new APIError(`Git Gateway Error: Please make sure Git Gateway is enabled on your site.`, error.status, 'Git Gateway'); } else { - console.error("Problem fetching repo data from GitHub"); + console.error("Problem fetching repo data from Git Gateway"); throw error; } }); @@ -70,11 +72,14 @@ export default class API extends GithubAPI { if (contentType && contentType.match(/json/)) { return this.parseJsonResponse(response); } - - return response.text(); + const text = response.text(); + if (!response.ok) { + return Promise.reject(text); + } + return text; }) .catch(error => { - throw new APIError(error.message, responseStatus, 'Git Gateway'); + throw new APIError((error.message || error.msg), responseStatus, 'Git Gateway'); }); } diff --git a/src/backends/github/API.js b/src/backends/github/API.js index 459524ddbb49..09d0b4fddf37 100644 --- a/src/backends/github/API.js +++ b/src/backends/github/API.js @@ -78,7 +78,11 @@ export default class API { if (contentType && contentType.match(/json/)) { return this.parseJsonResponse(response); } - return response.text(); + const text = response.text(); + if (!response.ok) { + return Promise.reject(text); + } + return text; }) .catch((error) => { throw new APIError(error.message, responseStatus, 'GitHub');