From 59b82178403986d04fc0094a7586ca21f5eaf6ab Mon Sep 17 00:00:00 2001 From: Martii Date: Wed, 21 Apr 2021 14:53:08 -0600 Subject: [PATCH] More error checking * 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 #1705 #37 and post #1799 Ref(s): * https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.8 * https://developer.mozilla.org/docs/Web/HTTP/Authentication --- controllers/user.js | 12 +++++++++--- libs/repoManager.js | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/controllers/user.js b/controllers/user.js index 186639679..c499262e8 100644 --- a/controllers/user.js +++ b/controllers/user.js @@ -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); @@ -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); @@ -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); diff --git a/libs/repoManager.js b/libs/repoManager.js index 65ddbcc9c..ff0fc4c5c 100644 --- a/libs/repoManager.js +++ b/libs/repoManager.js @@ -107,7 +107,7 @@ function fetchJSON(aPath, aCallback) { encodedAuth = Buffer.from(`${clientId}:${clientKey}`).toString('base64'); opts = { headers: { - authorization: `basic ${encodedAuth}` + Authorization: `Basic ${encodedAuth}` } }; }