Skip to content

Commit 8b618d8

Browse files
authored
fix(api): handle failing to send push notification (#930)
1 parent d6e0d05 commit 8b618d8

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

services/api/src/core/notifications/client/gateways/notification.web-push.gateway.ts

+17-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import { Injectable } from "@nestjs/common";
22
import { sendNotification, setVapidDetails } from "web-push";
33

4+
import { Logger } from "src/core/logging";
45
import { getRequiredStringConfig } from "src/utils/config.helper";
56

67
import { NotificationSubscriptionService } from "../../domain/services/notification-subscription.service";
78
import { INotification } from "../../types";
89

910
@Injectable()
1011
export class NotificationWebPushGateway {
12+
private logger = new Logger(NotificationWebPushGateway.name);
13+
1114
constructor(
1215
private readonly notificationSubscriptionService: NotificationSubscriptionService,
1316
) {
@@ -29,12 +32,20 @@ export class NotificationWebPushGateway {
2932
return false;
3033
}
3134

32-
const result = await sendNotification(
33-
pushSubscription,
34-
JSON.stringify(notification),
35-
);
36-
37-
return result.statusCode < 400;
35+
try {
36+
const result = await sendNotification(
37+
pushSubscription,
38+
JSON.stringify(notification),
39+
);
40+
41+
return result.statusCode < 400;
42+
} catch (error) {
43+
this.logger.error("Unable to send push notification", {
44+
error,
45+
notification,
46+
});
47+
return false;
48+
}
3849
}
3950

4051
public async sendWebPush(

0 commit comments

Comments
 (0)