Skip to content

Commit

Permalink
fix(events): fix error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
jtrein committed Sep 18, 2023
1 parent 4d726b4 commit 41eb6c1
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions server/events/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -43,17 +43,12 @@ const getSubscribersFromFile = async (): Promise<Subscribers> => {

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;
}
}

Expand All @@ -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));
Expand Down

0 comments on commit 41eb6c1

Please sign in to comment.