diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/notification/index.ts b/src/Umbraco.Web.UI.Client/src/packages/core/notification/index.ts index 526e0028f401..40980d113511 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/core/notification/index.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/core/notification/index.ts @@ -1,7 +1,5 @@ import './layouts/default/index.js'; export * from './controllers/peek-error/index.js'; -export * from '../resources/extractUmbNotificationColor.function.js'; -export * from './isUmbNotifications.function.js'; export * from './notification-handler.js'; export * from './notification.context.js'; diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/notification/isUmbNotifications.function.ts b/src/Umbraco.Web.UI.Client/src/packages/core/notification/isUmbNotifications.function.ts deleted file mode 100644 index ab861df6c2e4..000000000000 --- a/src/Umbraco.Web.UI.Client/src/packages/core/notification/isUmbNotifications.function.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { EventMessageTypeModel } from '@umbraco-cms/backoffice/external/backend-api'; - -/** - * @deprecated Import from `@umbraco-cms/backoffice/resources` instead. - */ -function objectIsUmbNotification(notification: unknown): notification is UmbNotificationsEventModel { - if (typeof notification !== 'object' || notification === null) { - return false; - } - const object = notification as UmbNotificationsEventModel; - return ( - typeof object.category === 'string' && - typeof object.message === 'string' && - typeof object.type === 'string' && - Object.values(EventMessageTypeModel).includes(object.type) - ); -} - -/** - * @deprecated Import from `@umbraco-cms/backoffice/resources` instead. - */ -export interface UmbNotificationsEventModel { - category: string; - message: string; - type: EventMessageTypeModel; -} - -/** - * @deprecated Import from `@umbraco-cms/backoffice/resources` instead. - */ -export function isUmbNotifications(notifications: Array): notifications is Array { - return notifications.every(objectIsUmbNotification); -} - -/** - * @deprecated Import from `@umbraco-cms/backoffice/resources` instead. - */ -export const UMB_NOTIFICATION_HEADER = 'umb-notifications'; diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/resources/api-interceptor.controller.ts b/src/Umbraco.Web.UI.Client/src/packages/core/resources/api-interceptor.controller.ts index aa54c5f841df..b4043cd5ea16 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/core/resources/api-interceptor.controller.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/core/resources/api-interceptor.controller.ts @@ -45,34 +45,40 @@ export class UmbApiInterceptorController extends UmbControllerBase { client.interceptors.response.use(async (response) => { if (response.ok) return response; - // Clones the response to read the body - const origResponse = response.clone(); - const error = await origResponse.json(); - if (!error) return response; - - // If the error is not an UmbError, we check if it is a problem details object - // Check if the error is a problem details object - if (!('type' in error) || !('title' in error) || !('status' in error)) { - // If not, we just return the response - return response; - } - // Handle 500 errors - we need to show a notification - if (origResponse.status === 500) { - let headline = error.title ?? error.name ?? 'Server Error'; - let message = 'A fatal server error occurred. If this continues, please reach out to your administrator.'; - - // Special handling for ObjectCacheAppCache corruption errors, which we are investigating - if ( - error.detail?.includes('ObjectCacheAppCache') || - error.detail?.includes('Umbraco.Cms.Infrastructure.Scoping.Scope.DisposeLastScope()') - ) { - headline = 'Please restart the server'; - message = - 'The Umbraco object cache is corrupt, but your action may still have been executed. Please restart the server to reset the cache. This is a work in progress.'; - } + if (response.status === 500) { + try { + // Clones the response to read the body + const origResponse = response.clone(); + const error = await origResponse.json(); + + if (!error) return response; - this.#peekError(headline, message, error.errors ?? error.detail); + // If the error is not an UmbError, we check if it is a problem details object + // Check if the error is a problem details object + if (!('type' in error) || !('title' in error) || !('status' in error)) { + // If not, we just return the response + return response; + } + + let headline = error.title ?? error.name ?? 'Server Error'; + let message = 'A fatal server error occurred. If this continues, please reach out to your administrator.'; + + // Special handling for ObjectCacheAppCache corruption errors, which we are investigating + if ( + error.detail?.includes('ObjectCacheAppCache') || + error.detail?.includes('Umbraco.Cms.Infrastructure.Scoping.Scope.DisposeLastScope()') + ) { + headline = 'Please restart the server'; + message = + 'The Umbraco object cache is corrupt, but your action may still have been executed. Please restart the server to reset the cache. This is a work in progress.'; + } + + this.#peekError(headline, message, error.errors ?? error.detail); + } catch (e) { + // Ignore JSON parse error + console.error('[Interceptor] Caught a 500 Error, but failed parsing error body (expected JSON)', e); + } } // Return original response