From 9203335963ce33c1a525020596657977841500db Mon Sep 17 00:00:00 2001 From: dbroqua Date: Mon, 30 Mar 2020 21:53:17 +0200 Subject: [PATCH] Trying to fix bug :") --- libs.js | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/libs.js b/libs.js index 2685aeb..02ff969 100644 --- a/libs.js +++ b/libs.js @@ -213,22 +213,26 @@ const getMedia = (coverUrl, callback) => { const dest = '/tmp/attachment.jpg' const file = fs.createWriteStream(dest) - request({ - uri: coverUrl, - headers: { - 'Cache-Control': 'max-age=0', - Connection: 'keep-alive', - 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36' - } - }) - .pipe(file) - .on('finish', () => { - callback(null, dest) - }) - .on('error', (error) => { - console.log(config.colors.FgRed, 'ERR:', error, config.colors.Reset) - callback(error) + try { + request({ + uri: coverUrl, + headers: { + 'Cache-Control': 'max-age=0', + Connection: 'keep-alive', + 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36' + } }) + .on('error', (error) => { + console.log(config.colors.FgRed, 'ERR:', error, config.colors.Reset) + callback(error) + }) + .pipe(file) + .on('finish', () => { + callback(null, dest) + }) + } catch (error) { + callback(error) + } } /**