From e0f1ee023e32d3da30937e82c5ce666d9981372b Mon Sep 17 00:00:00 2001 From: Uxio Fuentefria Date: Tue, 1 Aug 2023 12:13:49 +0200 Subject: [PATCH] Log webhooks when processing --- src/routes/events/events.service.ts | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/routes/events/events.service.ts b/src/routes/events/events.service.ts index deabf5c..8ce727c 100644 --- a/src/routes/events/events.service.ts +++ b/src/routes/events/events.service.ts @@ -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); } }