created view to present errors to client #232

Merged
bones7242 merged 1 commit from redesign-polish into master 2017-10-31 00:41:24 +01:00
3 changed files with 17 additions and 10 deletions

View file

@ -6,13 +6,13 @@ module.exports = {
logger.error(`Request Error: ${originalUrl}`, module.exports.useObjectPropertiesIfNoKeys(error)); logger.error(`Request Error: ${originalUrl}`, module.exports.useObjectPropertiesIfNoKeys(error));
postToStats(action, originalUrl, ip, null, null, error); postToStats(action, originalUrl, ip, null, null, error);
if (error.response) { 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') { } 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) { } else if (error.message) {
res.status(400).send(error.message); res.status(500).render('requestError', {message: error.message, status: 500});
} else { } else {
res.status(400).send(error); res.status(400).render('requestError', {message: error, status: 400});
} }
}, },
handlePublishError (error) { handlePublishError (error) {

View file

@ -1,11 +1,12 @@
const axios = require('axios'); const axios = require('axios');
const logger = require('winston'); const logger = require('winston');
function handleResponse ({ data }, resolve, reject) { function handleLbrynetResponse ({ data }, resolve, reject) {
logger.debug('handling lbry api response...'); logger.debug('lbry api data:', data);
if (data.result) { if (data.result) {
// check for an error // check for an error
if (data.result.error) { if (data.result.error) {
logger.debug('Lbrynet api error:', data.result.error);
reject(data.result.error); reject(data.result.error);
return; return;
}; };
@ -27,7 +28,7 @@ module.exports = {
params: publishParams, params: publishParams,
}) })
.then(response => { .then(response => {
handleResponse(response, resolve, reject); handleLbrynetResponse(response, resolve, reject);
}) })
.catch(error => { .catch(error => {
reject(error); reject(error);
@ -43,7 +44,7 @@ module.exports = {
params: { uri, timeout: 20 }, params: { uri, timeout: 20 },
}) })
.then(response => { .then(response => {
handleResponse(response, resolve, reject); handleLbrynetResponse(response, resolve, reject);
}) })
.catch(error => { .catch(error => {
reject(error); reject(error);
@ -59,7 +60,7 @@ module.exports = {
params: { name: claimName }, params: { name: claimName },
}) })
.then(response => { .then(response => {
handleResponse(response, resolve, reject); handleLbrynetResponse(response, resolve, reject);
}) })
.catch(error => { .catch(error => {
reject(error); reject(error);
@ -119,7 +120,7 @@ module.exports = {
}) })
.then(response => { .then(response => {
logger.verbose('createChannel response:', response); logger.verbose('createChannel response:', response);
handleResponse(response, resolve, reject); handleLbrynetResponse(response, resolve, reject);
}) })
.catch(error => { .catch(error => {
logger.error('createChannel error:', error); logger.error('createChannel error:', error);

View file

@ -0,0 +1,6 @@
<div class="row row--padded">
<h3>Error</h3>
<p>Unfortnately, Spee.ch encountered an error. You can help us out, by reporting the below error message in the #speech channel on <a class="link--primary" href="https://discord.gg/YjYbwhS" target="_blank">LBRY Discord</a>!</p>
<p>status: {{status}}</p>
<p>message: {{message}}</p>
</div>