File tree 1 file changed +17
-6
lines changed
services/api/src/core/notifications/client/gateways
1 file changed +17
-6
lines changed Original file line number Diff line number Diff line change 1
1
import { Injectable } from "@nestjs/common" ;
2
2
import { sendNotification , setVapidDetails } from "web-push" ;
3
3
4
+ import { Logger } from "src/core/logging" ;
4
5
import { getRequiredStringConfig } from "src/utils/config.helper" ;
5
6
6
7
import { NotificationSubscriptionService } from "../../domain/services/notification-subscription.service" ;
7
8
import { INotification } from "../../types" ;
8
9
9
10
@Injectable ( )
10
11
export class NotificationWebPushGateway {
12
+ private logger = new Logger ( NotificationWebPushGateway . name ) ;
13
+
11
14
constructor (
12
15
private readonly notificationSubscriptionService : NotificationSubscriptionService ,
13
16
) {
@@ -29,12 +32,20 @@ export class NotificationWebPushGateway {
29
32
return false ;
30
33
}
31
34
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
+ }
38
49
}
39
50
40
51
public async sendWebPush (
You can’t perform that action at this time.
0 commit comments