created error view to present errors to client
This commit is contained in:
parent
ff9379ffb7
commit
829ac91985
3 changed files with 17 additions and 10 deletions
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
|
|
6
views/requestError.handlebars
Normal file
6
views/requestError.handlebars
Normal 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>
|
Loading…
Reference in a new issue