spee.ch/helpers/libraries/errorHandlers.js

27 lines
884 B
JavaScript
Raw Normal View History

2017-06-20 04:34:34 +02:00
const logger = require('winston');
2017-06-03 09:41:02 +02:00
module.exports = {
handleRequestError (error, res) {
2017-06-22 08:33:03 +02:00
logger.error('Request Error >>', error);
if (error === 'NO_CLAIMS' || error === 'NO_FREE_PUBLIC_CLAIMS') {
res.status(307).render('noClaims');
} else if (error.response) {
res.status(error.response.status).send(error.response.data.error.message);
} else if (error.code === 'ECONNREFUSED') {
2017-06-27 02:16:46 +02:00
res.status(503).send('Connection refused. The daemon may not be running.');
} else {
2017-06-22 08:33:03 +02:00
res.status(400).send(JSON.stringify(error));
}
},
handlePublishError (error) {
2017-06-22 08:33:03 +02:00
logger.error('Publish Error >>', error);
if (error.code === 'ECONNREFUSED') {
return 'Connection refused. The daemon may not be running.';
} else if (error.response.data.error) {
return error.response.data.error;
} else {
return error;
}
},
};