From 1862f84b97af1bf53c18e8bc25bee0cd4fa65b12 Mon Sep 17 00:00:00 2001 From: bill bittner Date: Mon, 13 Nov 2017 15:12:16 -0500 Subject: [PATCH] updated error handler with destructuring --- helpers/errorHandlers.js | 25 ++++++++++++------------ public/assets/js/publishFileFunctions.js | 2 +- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/helpers/errorHandlers.js b/helpers/errorHandlers.js index 9aafc4b7..de970625 100644 --- a/helpers/errorHandlers.js +++ b/helpers/errorHandlers.js @@ -36,24 +36,18 @@ module.exports = { handleRequestError: function (action, originalUrl, ip, error, res) { logger.error(`Request Error on ${originalUrl}`, module.exports.useObjectPropertiesIfNoKeys(error)); postToStats(action, originalUrl, ip, null, null, error); - const errorStatusAndMessage = this.returnErrorMessageAndStatus(error); + const [status, message] = this.returnErrorMessageAndStatus(error); res - .status(errorStatusAndMessage[0]) - .render('requestError', { - status : errorStatusAndMessage[0], - message: errorStatusAndMessage[1], - }); + .status(status) + .render('requestError', this.createErrorResponsePayload(status, message)); }, handleApiError: function (action, originalUrl, ip, error, res) { logger.error(`Api ${action} Error on ${originalUrl}`, module.exports.useObjectPropertiesIfNoKeys(error)); postToStats(action, originalUrl, ip, null, null, error); - const errorStatusAndMessage = this.returnErrorMessageAndStatus(error); + const [status, message] = this.returnErrorMessageAndStatus(error); res - .status(errorStatusAndMessage[0]) - .json({ - success: false, - message: errorStatusAndMessage[1], - }); + .status(status) + .json(this.createErrorResponsePayload(status, message)); }, useObjectPropertiesIfNoKeys: function (err) { if (Object.keys(err).length === 0) { @@ -65,4 +59,11 @@ module.exports = { } return err; }, + createErrorResponsePayload (status, message) { + return { + status, + success: false, + message, + }; + }, }; diff --git a/public/assets/js/publishFileFunctions.js b/public/assets/js/publishFileFunctions.js index 199d2f3b..995b40a7 100644 --- a/public/assets/js/publishFileFunctions.js +++ b/public/assets/js/publishFileFunctions.js @@ -182,7 +182,7 @@ var publishFileFunctions = { this.updateUploadPercent('

Curious what magic is happening here? Learn more.

'); }, showFilePublishFailure: function (msg){ - this.updatePublishStatus('

Something went wrong...

' + msg + '

For help, post the above error text in the #speech channel on the lbry discord'); + this.updatePublishStatus('

Something went wrong...

' + msg + '

For help, post the above error text in the #speech channel on the lbry discord'); this.hidePublishProgressBar(); this.hideUploadPercent(); },