[backend/masto-client] Catch GracefulExceptions correctly in push handler

This commit is contained in:
Laura Hausmann 2024-03-27 17:56:07 +01:00
parent fa75409923
commit d4e8d7a6f6
No known key found for this signature in database
GPG key ID: D044E84C5BE01605

View file

@ -38,9 +38,10 @@ public class PushService(
await using var scope = scopeFactory.CreateAsyncScope(); await using var scope = scopeFactory.CreateAsyncScope();
await using var db = scope.ServiceProvider.GetRequiredService<DatabaseContext>(); await using var db = scope.ServiceProvider.GetRequiredService<DatabaseContext>();
var type = NotificationEntity.EncodeType(notification.Type);
var subscriptions = await db.PushSubscriptions.Where(p => p.User == notification.Notifiee) var subscriptions = await db.PushSubscriptions.Where(p => p.User == notification.Notifiee)
.Include(pushSubscription => pushSubscription.OauthToken) .Include(pushSubscription => pushSubscription.OauthToken)
.Where(p => p.Types.Contains(NotificationEntity.EncodeType(notification.Type))) .Where(p => p.Types.Contains(type))
.ToListAsync(); .ToListAsync();
if (subscriptions.Count == 0) if (subscriptions.Count == 0)
@ -58,8 +59,6 @@ public class PushService(
await db.Followings.AnyAsync(p => p.Follower == notification.Notifier && await db.Followings.AnyAsync(p => p.Follower == notification.Notifier &&
p.Followee == notification.Notifiee); p.Followee == notification.Notifiee);
try
{
var renderer = scope.ServiceProvider.GetRequiredService<NotificationRenderer>(); var renderer = scope.ServiceProvider.GetRequiredService<NotificationRenderer>();
var rendered = await renderer.RenderAsync(notification, notification.Notifiee); var rendered = await renderer.RenderAsync(notification, notification.Notifiee);
var name = rendered.Notifier.DisplayName; var name = rendered.Notifier.DisplayName;
@ -143,7 +142,6 @@ public class PushService(
{ {
// Unsupported notification type // Unsupported notification type
} }
}
catch (Exception e) catch (Exception e)
{ {
logger.LogError("Event handler MastodonPushHandler threw exception: {e}", e); logger.LogError("Event handler MastodonPushHandler threw exception: {e}", e);