clean up notification stuff

This commit is contained in:
m5r
2022-06-01 22:45:49 +02:00
parent 117a77525e
commit 68570ff3d4
7 changed files with 219 additions and 178 deletions

View File

@ -61,9 +61,10 @@ async function subscribe(request: Request) {
});
} catch (error: any) {
if (error.code !== "P2002") {
logger.error(error);
throw error;
}
logger.warn(`Duplicate insertion of subscription with endpoint=${subscription.endpoint}`);
}
return null;
@ -80,7 +81,15 @@ async function unsubscribe(request: Request) {
}
const endpoint = validation.data.subscriptionEndpoint;
await db.notificationSubscription.delete({ where: { endpoint } });
try {
await db.notificationSubscription.delete({ where: { endpoint } });
} catch (error: any) {
if (error.code !== "P2025") {
throw error;
}
logger.warn(`Could not delete subscription with endpoint=${endpoint} because it has already been deleted`);
}
return null;
}