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 41eb6c1 commit c397f0e
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 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, { AxiosError } from 'axios';
import axios, { AxiosError } from 'axios/dist/node/axios.cjs';

import db from '../helpers/postgres';

Expand Down Expand Up @@ -45,10 +45,16 @@ async function sendEvent(event, to) {
try {
await axios.post(to, event);
} catch (error) {
console.error(
`Failed to send event to ${to}`,
error instanceof AxiosError ? error.toJSON() : error
);
const BASE_ERROR = `Failed to send event to`;

if (error instanceof AxiosError) {
console.error(
BASE_ERROR,
error.response ? error.response.data : error.toJSON()
);
} else {
console.error(BASE_ERROR, error);
}
}
}

Expand Down

0 comments on commit c397f0e

Please sign in to comment.