errorhandling oder so

This commit is contained in:
Flummi 2018-09-02 16:51:32 +02:00
parent 305417b6d0
commit b1b1781bce

View File

@ -26,15 +26,15 @@ export default bot => {
const tmp = url.parse(link).path.substr(1); const tmp = url.parse(link).path.substr(1);
rp(apis.reverse + tmp) rp(apis.reverse + tmp)
.then(res => { .then(res => {
console.log(res); if(res.error)
return JSON.parse(res).id; throw res.error;
return JSON.parse(res).data.id;
}) })
.then(id => Promise.all([ .then(id => Promise.all([
rp(apis.pr0gag.list + id.toString()), rp(apis.pr0gag.list + id.toString()),
rp(apis.pr0gag.item + id.toString()), rp(apis.pr0gag.item + id.toString()),
id id
]) ]).then(([list, item, id]) => [
.then(([list, item, id]) => [
JSON.parse(list).items.filter(item => item.id === id)[0], JSON.parse(list).items.filter(item => item.id === id)[0],
JSON.parse(item), JSON.parse(item),
id id
@ -64,7 +64,10 @@ export default bot => {
`l: ${meta.link}` `l: ${meta.link}`
].join("; ")) ].join("; "))
.then(out => e.reply(out)) .then(out => e.reply(out))
); )
.catch(err => {
e.reply( JSON.stringify(err));
});
} }
})); }));
}; };