diff --git a/packages/backend/src/server/api/mastodon/MastodonConverters.ts b/packages/backend/src/server/api/mastodon/MastodonConverters.ts index 0e8ce5a2a7..e5d732ed79 100644 --- a/packages/backend/src/server/api/mastodon/MastodonConverters.ts +++ b/packages/backend/src/server/api/mastodon/MastodonConverters.ts @@ -351,12 +351,21 @@ export class MastodonConverters { }; } - public async convertNotification(notification: Entity.Notification, me: MiLocalUser | null): Promise { + public async convertNotification(notification: Entity.Notification, me: MiLocalUser | null): Promise { + const status = notification.status + ? await this.convertStatus(notification.status, me).catch(() => null) + : null; + + // We sometimes get notifications for inaccessible notes, these should be ignored. + if (!status) { + return null; + } + return { account: await this.convertAccount(notification.account), created_at: notification.created_at, id: notification.id, - status: notification.status ? await this.convertStatus(notification.status, me) : undefined, + status, type: convertNotificationType(notification.type as NotificationType), }; } diff --git a/packages/backend/src/server/api/mastodon/MastodonLogger.ts b/packages/backend/src/server/api/mastodon/MastodonLogger.ts index 57cf876dff..81d3e8f03d 100644 --- a/packages/backend/src/server/api/mastodon/MastodonLogger.ts +++ b/packages/backend/src/server/api/mastodon/MastodonLogger.ts @@ -35,7 +35,7 @@ export class MastodonLogger { // TODO move elsewhere export interface MastodonError { error: string; - error_description: string; + error_description?: string; } export function getErrorData(error: unknown): MastodonError { diff --git a/packages/backend/src/server/api/mastodon/endpoints/notifications.ts b/packages/backend/src/server/api/mastodon/endpoints/notifications.ts index c81b3ca236..c3108c8b3e 100644 --- a/packages/backend/src/server/api/mastodon/endpoints/notifications.ts +++ b/packages/backend/src/server/api/mastodon/endpoints/notifications.ts @@ -32,6 +32,9 @@ export class ApiNotificationsMastodon { const notifications = await Promise.all(data.data.map(n => this.mastoConverters.convertNotification(n, me))); const response: MastodonEntity.Notification[] = []; for (const notification of notifications) { + // Notifications for inaccessible notes will be null and should be ignored + if (!notification) continue; + response.push(notification); if (notification.type === 'reaction') { response.push({ @@ -52,6 +55,13 @@ export class ApiNotificationsMastodon { const data = await client.getNotification(_request.params.id); const response = await this.mastoConverters.convertNotification(data.data, me); + // Notifications for inaccessible notes will be null and should be ignored + if (!response) { + return reply.code(404).send({ + error: 'NOT_FOUND', + }); + } + reply.send(response); });