Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent login if Git Gateway is disabled. #1295

Merged
merged 1 commit into from
May 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Benaiah Is there any problem internally if we reject on not-OK responses for all content-types? We do on JSON responses already (see parseJsonResponse).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tech4him1 yeah - I actually thought it was supposed to be doing so already. If the caller is expecting a non-ok response it can catch the APIError.

return Promise.reject(text);
}
return text;
})
.catch((error) => {
throw new APIError(error.message, responseStatus, 'GitHub');
Expand Down