Skip to content

Commit

Permalink
More error checking
Browse files Browse the repository at this point in the history
* Transform GH 401 to 503 .  Mentioned at https://developer.github.com/changes/2020-02-10-deprecating-auth-through-query-param/ and encountered with newer migrated dep.
* Spec for authorization shows uppercasing... so new dep has it with incorrect casing I believe... may not matter on their server but consistancy here. Reverting.
* Add a few more important comments

Applies to OpenUserJS#1705 OpenUserJS#37 and post OpenUserJS#1799

Ref(s):
* https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.8
* https://developer.mozilla.org/docs/Web/HTTP/Authentication
  • Loading branch information
Martii committed Apr 21, 2021
1 parent c0cdd54 commit 59b8217
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
12 changes: 9 additions & 3 deletions controllers/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -1254,7 +1254,9 @@ exports.userGitHubRepoListPage = function (aReq, aRes, aNext) {
var msg = null;

if (aErr) {
switch (aErr.code) {
switch (aErr.code) { // NOTE: Important to test for GH code vs potential OUJS code
case 401:
// fallsthrough
case 403:
try {
msg = JSON.parse(aErr.message);
Expand Down Expand Up @@ -1398,7 +1400,9 @@ exports.userGitHubRepoPage = function (aReq, aRes, aNext) {
var msg = null;

if (aErr) {
switch (aErr.code) {
switch (aErr.code) { // NOTE: Important to test for GH code vs potential OUJS code
case 401:
// fallsthrough
case 403:
try {
msg = JSON.parse(aErr.message);
Expand Down Expand Up @@ -1766,7 +1770,9 @@ exports.userGitHubImportScriptPage = function (aReq, aRes, aNext) {
}

if (!(aErr instanceof String)) {
switch (aErr.code) { // NOTE: Important to test for GH 403 vs potential OUJS 403
switch (aErr.code) { // NOTE: Important to test for GH code vs potential OUJS code
case 401:
// fallsthrough
case 403:
try {
msg = JSON.parse(aErr.message);
Expand Down
2 changes: 1 addition & 1 deletion libs/repoManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ function fetchJSON(aPath, aCallback) {
encodedAuth = Buffer.from(`${clientId}:${clientKey}`).toString('base64');
opts = {
headers: {
authorization: `basic ${encodedAuth}`
Authorization: `Basic ${encodedAuth}`
}
};
}
Expand Down

0 comments on commit 59b8217

Please sign in to comment.