2018-04-27 08:42:22 +02:00
|
|
|
const logger = require('winston');
|
|
|
|
|
|
|
|
const handleLbrynetResponse = ({ data }, resolve, reject) => {
|
|
|
|
logger.debug('lbry api data:', data);
|
2018-09-28 00:12:17 +02:00
|
|
|
if (data) {
|
2018-04-27 08:42:22 +02:00
|
|
|
// check for an error
|
2018-09-28 00:12:17 +02:00
|
|
|
if (data.error) {
|
|
|
|
logger.debug('Lbrynet api error:', data.error);
|
|
|
|
reject(new Error(data.error.message));
|
2018-04-27 08:42:22 +02:00
|
|
|
return;
|
2018-09-28 00:12:17 +02:00
|
|
|
}
|
2018-04-27 08:42:22 +02:00
|
|
|
resolve(data.result);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// fallback in case it just timed out
|
|
|
|
reject(JSON.stringify(data));
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = handleLbrynetResponse;
|