diff --git a/app/worker.ts b/app/worker.ts index 357d171..5890528 100644 --- a/app/worker.ts +++ b/app/worker.ts @@ -136,19 +136,31 @@ export default function start(self: ServiceWorkerGlobalScope) { subscription: PushSubscription, db: ReturnType ) { - const response = await fetch(`${process.env.BASE_URL}/api/subscription/`, { - method: "POST", - body: JSON.stringify(subscription), - }) + try { + await sendMessage({ + message: `URL ${process.env.BASE_URL}/api/subscription/`, + }) - await sendMessage({ - message: `Response status ${response.status}`, - }) + const response = await fetch( + `${process.env.BASE_URL}/api/subscription/`, + { + method: "POST", + body: JSON.stringify(subscription), + } + ) - db.subscriptions.put({ - id: 1, - subscriptionId: (await response.json()).subscriptionId, - }) + await sendMessage({ + message: `Response status ${response.status}`, + }) + db.subscriptions.put({ + id: 1, + subscriptionId: (await response.json()).subscriptionId, + }) + } catch (error) { + await sendMessage({ + message: `ERRRROR ${(error as Error).toString()}}`, + }) + } } function putSubscription(subscription: PushSubscription, id: number) {