From 0616b3c3b07faa5f69bef4582b6d26471711bcb6 Mon Sep 17 00:00:00 2001 From: softsimon Date: Sun, 15 Nov 2020 14:31:34 +0700 Subject: [PATCH] Axios error handle sponsor proxy requests. --- backend/src/index.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/backend/src/index.ts b/backend/src/index.ts index 81fad61bc..f7591ecf6 100644 --- a/backend/src/index.ts +++ b/backend/src/index.ts @@ -191,12 +191,20 @@ class Server { } else { this.app .get(config.MEMPOOL.API_URL_PREFIX + 'donations', async (req, res) => { - const response = await axios.get('https://mempool.space/api/v1/donations', { responseType: 'stream' }); - response.data.pipe(res); + try { + const response = await axios.get('https://mempool.space/api/v1/donations', { responseType: 'stream' }); + response.data.pipe(res); + } catch (e) { + res.status(500).end(); + } }) .get(config.MEMPOOL.API_URL_PREFIX + 'donations/images/:id', async (req, res) => { - const response = await axios.get('https://mempool.space/api/v1/donations/images/' + req.params.id, { responseType: 'stream' }); - response.data.pipe(res); + try { + const response = await axios.get('https://mempool.space/api/v1/donations/images/' + req.params.id, { responseType: 'stream' }); + response.data.pipe(res); + } catch (e) { + res.status(500).end(); + } }); } }