From 829ac91985778240c91b88abfbc00c77712eaf04 Mon Sep 17 00:00:00 2001 From: bill bittner Date: Mon, 30 Oct 2017 16:38:57 -0700 Subject: [PATCH] created error view to present errors to client --- helpers/errorHandlers.js | 8 ++++---- helpers/lbryApi.js | 13 +++++++------ views/requestError.handlebars | 6 ++++++ 3 files changed, 17 insertions(+), 10 deletions(-) create mode 100644 views/requestError.handlebars diff --git a/helpers/errorHandlers.js b/helpers/errorHandlers.js index b127cd90..3778eeeb 100644 --- a/helpers/errorHandlers.js +++ b/helpers/errorHandlers.js @@ -6,13 +6,13 @@ module.exports = { logger.error(`Request Error: ${originalUrl}`, module.exports.useObjectPropertiesIfNoKeys(error)); postToStats(action, originalUrl, ip, null, null, error); if (error.response) { - res.status(error.response.status).send(error.response.data.error.message); + res.status(error.response.status).render('requestError', {message: error.response.data.error.message, status: error.response.status}); } else if (error.code === 'ECONNREFUSED') { - res.status(503).send('Connection refused. The daemon may not be running.'); + res.status(503).render('requestError', {message: 'Connection refused. The daemon may not be running.', status: 503}); } else if (error.message) { - res.status(400).send(error.message); + res.status(500).render('requestError', {message: error.message, status: 500}); } else { - res.status(400).send(error); + res.status(400).render('requestError', {message: error, status: 400}); } }, handlePublishError (error) { diff --git a/helpers/lbryApi.js b/helpers/lbryApi.js index e342a0eb..bfd3139c 100644 --- a/helpers/lbryApi.js +++ b/helpers/lbryApi.js @@ -1,11 +1,12 @@ const axios = require('axios'); const logger = require('winston'); -function handleResponse ({ data }, resolve, reject) { - logger.debug('handling lbry api response...'); +function handleLbrynetResponse ({ data }, resolve, reject) { + logger.debug('lbry api data:', data); if (data.result) { // check for an error if (data.result.error) { + logger.debug('Lbrynet api error:', data.result.error); reject(data.result.error); return; }; @@ -27,7 +28,7 @@ module.exports = { params: publishParams, }) .then(response => { - handleResponse(response, resolve, reject); + handleLbrynetResponse(response, resolve, reject); }) .catch(error => { reject(error); @@ -43,7 +44,7 @@ module.exports = { params: { uri, timeout: 20 }, }) .then(response => { - handleResponse(response, resolve, reject); + handleLbrynetResponse(response, resolve, reject); }) .catch(error => { reject(error); @@ -59,7 +60,7 @@ module.exports = { params: { name: claimName }, }) .then(response => { - handleResponse(response, resolve, reject); + handleLbrynetResponse(response, resolve, reject); }) .catch(error => { reject(error); @@ -119,7 +120,7 @@ module.exports = { }) .then(response => { logger.verbose('createChannel response:', response); - handleResponse(response, resolve, reject); + handleLbrynetResponse(response, resolve, reject); }) .catch(error => { logger.error('createChannel error:', error); diff --git a/views/requestError.handlebars b/views/requestError.handlebars new file mode 100644 index 00000000..83e56144 --- /dev/null +++ b/views/requestError.handlebars @@ -0,0 +1,6 @@ +
+

Error

+

Unfortnately, Spee.ch encountered an error. You can help us out, by reporting the below error message in the #speech channel on LBRY Discord!

+

status: {{status}}

+

message: {{message}}

+
-- 2.45.2