improvement: clear error if Git Gateway settings 404

This commit is contained in:
Caleb 2018-08-29 19:44:01 -06:00 committed by GitHub
parent 4f3116de4d
commit 424a49e36c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -90,7 +90,20 @@ export default class GitGateway {
{
headers: { Authorization: `Bearer ${token}` },
},
).then(res => res.json());
).then(async res => {
const contentType = res.headers.get('Content-Type');
if (contentType !== 'application/json' && contentType !== 'text/json') {
throw new APIError(`Your Git Gateway backend is not returning valid settings. Please make sure it is enabled.`, res.status, 'Git Gateway');
}
const body = await res.json();
if (!res.ok) {
throw new APIError(`Git Gateway Error: ${(body.message ? body.message : body)}`, res.status, 'Git Gateway');
}
return body;
});
this.acceptRoles = roles;
if (github_enabled) {
this.backendType = 'github';