Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Handle error from void promises #432

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading