From f8a895123329d318ed6c370cdefe347725412359 Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Mon, 22 Jun 2026 20:18:59 +0300 Subject: [PATCH] notificatiosn error handling --- src/services/errors/errors.js | 3 +- .../notifications_fetcher.service.js | 28 ++++++++----------- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/src/services/errors/errors.js b/src/services/errors/errors.js index 12d32c12b..546554cf1 100644 --- a/src/services/errors/errors.js +++ b/src/services/errors/errors.js @@ -13,9 +13,10 @@ function humanizeErrors(errors) { export function StatusCodeError(statusCode, body, options, response) { this.name = 'StatusCodeError' this.statusCode = statusCode + this.statusText = body.error.error || body.error this.details = JSON && JSON.stringify ? JSON.stringify(body) : body this.errorData = body.error - this.message = statusCode + ' - ' + body.error.error || body.error + this.message = statusCode + ' - ' + statusText this.error = body // legacy attribute this.options = options this.response = response diff --git a/src/services/notifications_fetcher/notifications_fetcher.service.js b/src/services/notifications_fetcher/notifications_fetcher.service.js index bb94599eb..f787b92e4 100644 --- a/src/services/notifications_fetcher/notifications_fetcher.service.js +++ b/src/services/notifications_fetcher/notifications_fetcher.service.js @@ -83,27 +83,23 @@ const fetchAndUpdate = ({ store, credentials, older = false, sinceId }) => { const fetchNotifications = ({ store, args, older }) => { return fetchTimeline(args) .then((response) => { - if (response.errors) { - if ( - response.status === 400 && - response.statusText.includes('Invalid value for enum') - ) { - response.statusText - .matchAll(/(\w+) - Invalid value for enum./g) - .toArray() - .map((x) => x[1]) - .forEach((x) => mastoApiNotificationTypes.delete(x)) - return fetchNotifications({ store, args, older }) - } else { - throw new Error(`${response.status} ${response.statusText}`) - } - } - const notifications = response.data update({ store, notifications, older }) return notifications }) .catch((error) => { + if ( + error.statusCode === 400 && + error.statusText.includes('Invalid value for enum') + ) { + error.statusText + .matchAll(/(\w+) - Invalid value for enum./g) + .toArray() + .map((x) => x[1]) + .forEach((x) => mastoApiNotificationTypes.delete(x)) + return fetchNotifications({ store, args, older }) + } + useInterfaceStore().pushGlobalNotice({ level: 'error', messageKey: 'notifications.error',