aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/notifications.js38
-rw-r--r--lib/webhooks.js10
2 files changed, 29 insertions, 19 deletions
diff --git a/lib/notifications.js b/lib/notifications.js
index 9c9c95dc..8f092c5c 100644
--- a/lib/notifications.js
+++ b/lib/notifications.js
@@ -9,24 +9,30 @@ if (config.vapid) {
);
}
-export const notify = (user, payload) => {
- let { subscriptions } = user;
+export const notify = async (user, payload) => {
+ try {
+ let { subscriptions } = user;
- if (subscriptions) {
- subscriptions.map(async (subscription, i) => {
- try {
- await webpush.sendNotification(subscription, payload);
- } catch (e) {
- if (
- e.body &&
- (e.body.includes("expired") || e.body.includes("No such"))
- ) {
- user.subscriptions.splice(i, 1);
- await user.save();
- } else {
- err("problem sending notification", e);
+ if (subscriptions) {
+ let i = 0;
+ for (let subscription of subscriptions) {
+ i++;
+ try {
+ await webpush.sendNotification(subscription, payload);
+ } catch (e) {
+ if (
+ e.body &&
+ (e.body.includes("expired") || e.body.includes("No such"))
+ ) {
+ user.subscriptions.splice(i, 1);
+ await user.save();
+ } else {
+ err("problem sending notification", e);
+ }
}
}
- });
+ }
+ } catch (e) {
+ console.log("problem notifying", e);
}
};
diff --git a/lib/webhooks.js b/lib/webhooks.js
index 901bd264..51a9a99e 100644
--- a/lib/webhooks.js
+++ b/lib/webhooks.js
@@ -2,7 +2,8 @@ import config from "$config";
import wretch from "./wretch";
import { l } from "$lib/logging";
-export const callWebhook = (invoice, payment) => {
+export const callWebhook = async (invoice, payment) => {
+ try {
if (!invoice || !payment) return;
let { address, received, text, webhook } = invoice;
@@ -13,7 +14,7 @@ export const callWebhook = (invoice, payment) => {
let secret = config.webhooks[webhook];
l("calling webhook", webhook, amount, hash, address, text);
- return wretch()
+ let res = await wretch()
.headers({ "x-webhook": secret })
.url(webhook)
.post({
@@ -28,6 +29,9 @@ export const callWebhook = (invoice, payment) => {
webhook
})
.res()
- .catch(console.log);
+ return res;
}
+ } catch(e) {
+ console.log("problem calling webhook", e)
+ }
};