From 0de49e2a75d99475f28a395447c3fc98d22a599a Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Thu, 21 May 2020 17:18:46 +0100 Subject: [PATCH] Ensure auth failure on project fetch identifies the remote Fixes #2545 --- packages/node_modules/@node-red/editor-api/lib/util.js | 10 ++++++++-- .../lib/storage/localfilesystem/projects/Project.js | 4 +++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/node_modules/@node-red/editor-api/lib/util.js b/packages/node_modules/@node-red/editor-api/lib/util.js index 0cef96bbb..950e3d9cc 100644 --- a/packages/node_modules/@node-red/editor-api/lib/util.js +++ b/packages/node_modules/@node-red/editor-api/lib/util.js @@ -43,10 +43,16 @@ module.exports = { rejectHandler: function(req,res,err) { //TODO: why this when errorHandler also?! log.audit({event: "api.error",error:err.code||"unexpected_error",message:err.message||err.toString()},req); - res.status(err.status||400).json({ + var response = { code: err.code||"unexpected_error", message: err.message||err.toString() - }); + }; + // Handle auth failures on a specific remote + // TODO: don't hardcode this here - allow users of rejectHandler to identify extra props to send + if (err.remote) { + response.remote = err.remote; + } + res.status(err.status||400).json(response); }, getRequestLogObject: function(req) { return { diff --git a/packages/node_modules/@node-red/runtime/lib/storage/localfilesystem/projects/Project.js b/packages/node_modules/@node-red/runtime/lib/storage/localfilesystem/projects/Project.js index 7ba3bd2f3..ad3c0bf26 100644 --- a/packages/node_modules/@node-red/runtime/lib/storage/localfilesystem/projects/Project.js +++ b/packages/node_modules/@node-red/runtime/lib/storage/localfilesystem/projects/Project.js @@ -706,7 +706,9 @@ Project.prototype.fetch = function(user,remoteName) { promise = promise.then(function() { return gitTools.fetch(project.path,remote,authCache.get(project.name,project.remotes[remote].fetch,username)) }).catch(function(err) { - err.remote = remote; + if (!err.remote) { + err.remote = remote; + } throw err; }) });