Skip to content

Commit b71de4d

Browse files
tech4him1brianlmacdonald
authored andcommitted
Prevent login if Git Gateway is disabled. (decaporg#1295)
1 parent 4aeab7b commit b71de4d

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

src/backends/git-gateway/API.js

+10-5
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@ export default class API extends GithubAPI {
1616
.catch(error => {
1717
if (error.status === 401) {
1818
if (error.message === "Bad credentials") {
19-
throw new Error("Git Gateway Error: Please ask your site administrator to reissue the Git Gateway token.");
19+
throw new APIError("Git Gateway Error: Please ask your site administrator to reissue the Git Gateway token.", error.status, 'Git Gateway');
2020
} else {
2121
return false;
2222
}
23+
} else if (error.status === 404 && (error.message === undefined || error.message === "Unable to locate site configuration")) {
24+
throw new APIError(`Git Gateway Error: Please make sure Git Gateway is enabled on your site.`, error.status, 'Git Gateway');
2325
} else {
24-
console.error("Problem fetching repo data from GitHub");
26+
console.error("Problem fetching repo data from Git Gateway");
2527
throw error;
2628
}
2729
});
@@ -70,11 +72,14 @@ export default class API extends GithubAPI {
7072
if (contentType && contentType.match(/json/)) {
7173
return this.parseJsonResponse(response);
7274
}
73-
74-
return response.text();
75+
const text = response.text();
76+
if (!response.ok) {
77+
return Promise.reject(text);
78+
}
79+
return text;
7580
})
7681
.catch(error => {
77-
throw new APIError(error.message, responseStatus, 'Git Gateway');
82+
throw new APIError((error.message || error.msg), responseStatus, 'Git Gateway');
7883
});
7984
}
8085

src/backends/github/API.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,11 @@ export default class API {
7979
if (contentType && contentType.match(/json/)) {
8080
return this.parseJsonResponse(response);
8181
}
82-
return response.text();
82+
const text = response.text();
83+
if (!response.ok) {
84+
return Promise.reject(text);
85+
}
86+
return text;
8387
})
8488
.catch((error) => {
8589
throw new APIError(error.message, responseStatus, 'GitHub');

0 commit comments

Comments
 (0)