Skip to content

Commit

Permalink
Log webhooks when processing
Browse files Browse the repository at this point in the history
  • Loading branch information
Uxio0 committed Aug 1, 2023
1 parent 629fd92 commit e0f1ee0
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/routes/events/events.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,23 @@ export class EventsService implements OnApplicationBootstrap {
}

processEvent(message: string): Promise<(AxiosResponse | undefined)[]> {
const txServiceEvent: TxServiceEvent = JSON.parse(message);
this.logger.log(`Processing event ${message}`);
let txServiceEvent: TxServiceEvent;
try {
txServiceEvent = JSON.parse(message);
} catch (err) {
this.logger.error(`Cannot parse message as JSON: ${message}`);
return Promise.resolve([undefined]);
}

// Check message is valid
if (this.isEventValid(txServiceEvent)) {
return this.webhookService.postEveryWebhook(txServiceEvent);
if (!this.isEventValid(txServiceEvent)) {
this.logger.error(
`Unsupported message. A valid message should have at least 'chainId' and 'type': ${message}`,
);
return Promise.resolve([undefined]);
}
this.logger.error(
'Unsupported message. A valid message should have at least `chainId` and `type`',
message,
);
return Promise.resolve([undefined]);

return this.webhookService.postEveryWebhook(txServiceEvent);
}
}

0 comments on commit e0f1ee0

Please sign in to comment.