Skip to content

Commit

Permalink
Merge pull request #432 from g-ongenae/fixture/handle-error-from-void…
Browse files Browse the repository at this point in the history
…-promises

[FIX] Handle error from void promises
  • Loading branch information
g-ongenae authored Oct 28, 2024
2 parents d4f2fcf + d4bd3aa commit 3a0de2f
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions src/hooks/services/hooks.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,13 @@ export class HooksService {
}

// Handle the event asynchronously
void this.dispatchAndHandleWebhook(event, subscription, serviceAccount, aggregationStartDate);
void this.dispatchAndHandleWebhook(event, subscription, serviceAccount, aggregationStartDate)
.catch((err: Error) => {
this.logger.error({
message: `Error while processing the event ${event.id}`,
error: err?.stack ?? err,
});
});

return;
}
Expand Down Expand Up @@ -125,17 +131,35 @@ export class HooksService {
break;
// The default case should never be reached, as the eventName is already checked in the DTO
default:
void se.update({ status: EventStatus.FAILED });
void se.update({ status: EventStatus.FAILED })
.catch((statusError: Error) => {
this.logger.error({
message: `Unable to update the event ${event.id}'s status to FAILED`,
error: statusError?.stack ?? statusError,
});
});

return;
}
} catch (err) {
void se.update({ status: EventStatus.ERROR });
void se.update({ status: EventStatus.ERROR })
.catch((statusError: Error) => {
this.logger.error({
message: `Unable to update the event ${event.id}'s status to ERROR`,
error: statusError?.stack ?? statusError,
});
});

throw err;
}

void se.update({ status: EventStatus.PROCESSED });
void se.update({ status: EventStatus.PROCESSED })
.catch((statusError: Error) => {
this.logger.error({
message: `Unable to update the event ${event.id}'s status to PROCESSED`,
error: statusError?.stack ?? statusError,
});
});
}

/**
Expand Down

0 comments on commit 3a0de2f

Please sign in to comment.