From b71de4de4eab7c99f9763041cae313b2943e7d96 Mon Sep 17 00:00:00 2001 From: Caleb Date: Tue, 15 May 2018 16:34:42 -0600 Subject: [PATCH] Prevent login if Git Gateway is disabled. (#1295) --- 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 783bb04171ac..3dc765529a89 100644 --- a/src/backends/github/API.js +++ b/src/backends/github/API.js @@ -79,7 +79,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');