From 41eb6c1a3fec1ef74266935856e789c90e2be092 Mon Sep 17 00:00:00 2001 From: Jeremiah Naylor-Trein Date: Mon, 18 Sep 2023 17:22:10 +0100 Subject: [PATCH] fix(events): fix error handling --- server/events/index.ts | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/server/events/index.ts b/server/events/index.ts index 6bc19249..40da8c75 100644 --- a/server/events/index.ts +++ b/server/events/index.ts @@ -7,7 +7,7 @@ * @see https://github.com/snapshot-labs/snapshot-hub/tree/master/src/events */ -import axios from 'axios'; +import axios, { AxiosError } from 'axios'; import db from '../helpers/postgres'; @@ -43,17 +43,12 @@ const getSubscribersFromFile = async (): Promise => { async function sendEvent(event, to) { try { - const { data } = await axios.post(to, event); - - return data; + await axios.post(to, event); } catch (error) { - // Attempt to print error from Axios console.error( `Failed to send event to ${to}`, - error.response ? error.repsonse.data : error.message + error instanceof AxiosError ? error.toJSON() : error ); - - return undefined; } } @@ -76,7 +71,7 @@ async function processEvents() { subscriber => !subscriber.spaces || subscriber.spaces.includes(event.space) ) - .map(subscriber => sendEvent(event, subscriber.url)) + .map(async subscriber => await sendEvent(event, subscriber.url)) ) .then(() => console.log('Process event done')) .catch(e => console.log('Process event failed', e));