diff --git a/Client/httpInterface.js b/Client/httpInterface.js index 868755e4d..2a968bdd2 100644 --- a/Client/httpInterface.js +++ b/Client/httpInterface.js @@ -539,7 +539,7 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE fs.mkdirSync(filePath) } catch (err) { if (err.message.indexOf('file already exists') < 0) { - throw(err) + throw (err) } } fs.writeFileSync(filePath + '/' + fileName, fileContent) @@ -599,8 +599,14 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE contribute() async function contribute() { - await doGit() - await doGithub() + if (await doGit() === false) { + respondWithContent(JSON.stringify(global.DEFAULT_FAIL_RESPONSE), httpResponse) + return + } + if (await doGithub() === false) { + respondWithContent(JSON.stringify(global.DEFAULT_FAIL_RESPONSE), httpResponse) + return + } respondWithContent(JSON.stringify(global.DEFAULT_OK_RESPONSE), httpResponse) } @@ -617,10 +623,14 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE await git.add('./*') await git.commit(commitMessage) await git.push('origin', currentBranch) + return true } catch (err) { - console.log('[ERROR] Error running Contribute.') - console.log(err.stack) - throw (err) + console.log('[ERROR] httpInterface -> App -> Contribute -> doGit -> Method call produced an error.') + console.log('[ERROR] httpInterface -> App -> Contribute -> doGit -> err.stack = ' + err.stack) + console.log('[ERROR] httpInterface -> App -> Contribute -> doGit -> commitMessage = ' + commitMessage) + console.log('[ERROR] httpInterface -> App -> Contribute -> doGit -> currentBranch = ' + currentBranch) + console.log('[ERROR] httpInterface -> App -> Contribute -> doGit -> contributionsBranch = ' + contributionsBranch) + return false } } @@ -647,9 +657,20 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE head, base, }); + return true } catch (err) { - if (err.stack.indexOf('A pull request already exists') < 0) { - throw (err) + if (err.stack.indexOf('A pull request already exists') >= 0) { + return true + } else { + console.log('[ERROR] httpInterface -> App -> Contribute -> doGithub -> Method call produced an error.') + console.log('[ERROR] httpInterface -> App -> Contribute -> doGithub -> err.stack = ' + err.stack) + console.log('[ERROR] httpInterface -> App -> Contribute -> doGithub -> commitMessage = ' + commitMessage) + console.log('[ERROR] httpInterface -> App -> Contribute -> doGithub -> username = ' + username) + console.log('[ERROR] httpInterface -> App -> Contribute -> doGithub -> token starts with = ' + token.substring(0, 10) + '...') + console.log('[ERROR] httpInterface -> App -> Contribute -> doGithub -> token ends with = ' + '...' + token.substring(token.length - 10)) + console.log('[ERROR] httpInterface -> App -> Contribute -> doGithub -> currentBranch = ' + currentBranch) + console.log('[ERROR] httpInterface -> App -> Contribute -> doGithub -> contributionsBranch = ' + contributionsBranch) + return false } } } @@ -660,6 +681,8 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE console.log('[ERROR] httpInterface -> App -> Contribute -> commitMessage = ' + commitMessage) console.log('[ERROR] httpInterface -> App -> Contribute -> username = ' + username) console.log('[ERROR] httpInterface -> App -> Contribute -> token = ' + token) + console.log('[ERROR] httpInterface -> App -> Contribute -> currentBranch = ' + currentBranch) + console.log('[ERROR] httpInterface -> App -> Contribute -> contributionsBranch = ' + contributionsBranch) let error = { result: 'Fail Because',