Skip to content

Commit

Permalink
Prevent login if Git Gateway is disabled. (#1295)
Browse files Browse the repository at this point in the history
  • Loading branch information
tech4him1 authored and erquhart committed May 15, 2018
1 parent c6bbfa7 commit 80817e2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
15 changes: 10 additions & 5 deletions src/backends/git-gateway/API.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
});
Expand Down Expand Up @@ -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');
});
}

Expand Down
6 changes: 5 additions & 1 deletion src/backends/github/API.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit 80817e2

Please sign in to comment.