2017-06-20 04:34:34 +02:00
|
|
|
const logger = require('winston');
|
|
|
|
|
2017-06-03 09:41:02 +02:00
|
|
|
module.exports = {
|
2017-06-17 22:51:30 +02:00
|
|
|
handleRequestError (error, res) {
|
2017-06-22 08:33:03 +02:00
|
|
|
logger.error('Request Error >>', error);
|
2017-06-17 22:51:30 +02:00
|
|
|
if (error === 'NO_CLAIMS' || error === 'NO_FREE_PUBLIC_CLAIMS') {
|
2017-06-19 18:37:35 +02:00
|
|
|
res.status(307).render('noClaims');
|
2017-06-17 22:51:30 +02:00
|
|
|
} else if (error.response) {
|
2017-06-19 18:37:35 +02:00
|
|
|
res.status(error.response.status).send(error.response.data.error.message);
|
2017-06-17 22:51:30 +02:00
|
|
|
} 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.');
|
2017-06-17 22:51:30 +02:00
|
|
|
} else {
|
2017-06-22 08:33:03 +02:00
|
|
|
res.status(400).send(JSON.stringify(error));
|
2017-06-17 22:51:30 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
handlePublishError (error) {
|
|
|
|
if (error.code === 'ECONNREFUSED') {
|
2017-06-28 06:32:05 +02:00
|
|
|
logger.error('Publish Error:', 'Connection refused. The daemon may not be running.');
|
2017-06-19 18:37:35 +02:00
|
|
|
return 'Connection refused. The daemon may not be running.';
|
2017-06-17 22:51:30 +02:00
|
|
|
} else if (error.response.data.error) {
|
2017-06-28 06:32:05 +02:00
|
|
|
logger.error('Publish Error:', error.response.data.error);
|
|
|
|
return error.response.data.error.message;
|
2017-06-17 22:51:30 +02:00
|
|
|
} else {
|
2017-06-28 06:32:05 +02:00
|
|
|
logger.error('Unhandled Publish Error:', error);
|
2017-06-19 18:37:35 +02:00
|
|
|
return error;
|
2017-06-17 22:51:30 +02:00
|
|
|
}
|
|
|
|
},
|
2017-06-19 18:37:35 +02:00
|
|
|
};
|