Skip to content

Commit fd1761d

Browse files
authored
V16: API error interceptor should return early if it will not execute (#18963)
* fix: resolves an unintended circular reference based on files being moved around introduced in #18939 * fix: improves error handling to return early if interceptor does not catch a 500 * fix: adds try/catch around json parsing
1 parent 6630220 commit fd1761d

File tree

3 files changed

+32
-66
lines changed

3 files changed

+32
-66
lines changed

src/Umbraco.Web.UI.Client/src/packages/core/notification/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import './layouts/default/index.js';
22
export * from './controllers/peek-error/index.js';
3-
export * from '../resources/extractUmbNotificationColor.function.js';
4-
export * from './isUmbNotifications.function.js';
53
export * from './notification-handler.js';
64
export * from './notification.context.js';
75

src/Umbraco.Web.UI.Client/src/packages/core/notification/isUmbNotifications.function.ts

Lines changed: 0 additions & 38 deletions
This file was deleted.

src/Umbraco.Web.UI.Client/src/packages/core/resources/api-interceptor.controller.ts

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -45,34 +45,40 @@ export class UmbApiInterceptorController extends UmbControllerBase {
4545
client.interceptors.response.use(async (response) => {
4646
if (response.ok) return response;
4747

48-
// Clones the response to read the body
49-
const origResponse = response.clone();
50-
const error = await origResponse.json();
51-
if (!error) return response;
52-
53-
// If the error is not an UmbError, we check if it is a problem details object
54-
// Check if the error is a problem details object
55-
if (!('type' in error) || !('title' in error) || !('status' in error)) {
56-
// If not, we just return the response
57-
return response;
58-
}
59-
6048
// Handle 500 errors - we need to show a notification
61-
if (origResponse.status === 500) {
62-
let headline = error.title ?? error.name ?? 'Server Error';
63-
let message = 'A fatal server error occurred. If this continues, please reach out to your administrator.';
64-
65-
// Special handling for ObjectCacheAppCache corruption errors, which we are investigating
66-
if (
67-
error.detail?.includes('ObjectCacheAppCache') ||
68-
error.detail?.includes('Umbraco.Cms.Infrastructure.Scoping.Scope.DisposeLastScope()')
69-
) {
70-
headline = 'Please restart the server';
71-
message =
72-
'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.';
73-
}
49+
if (response.status === 500) {
50+
try {
51+
// Clones the response to read the body
52+
const origResponse = response.clone();
53+
const error = await origResponse.json();
54+
55+
if (!error) return response;
7456

75-
this.#peekError(headline, message, error.errors ?? error.detail);
57+
// If the error is not an UmbError, we check if it is a problem details object
58+
// Check if the error is a problem details object
59+
if (!('type' in error) || !('title' in error) || !('status' in error)) {
60+
// If not, we just return the response
61+
return response;
62+
}
63+
64+
let headline = error.title ?? error.name ?? 'Server Error';
65+
let message = 'A fatal server error occurred. If this continues, please reach out to your administrator.';
66+
67+
// Special handling for ObjectCacheAppCache corruption errors, which we are investigating
68+
if (
69+
error.detail?.includes('ObjectCacheAppCache') ||
70+
error.detail?.includes('Umbraco.Cms.Infrastructure.Scoping.Scope.DisposeLastScope()')
71+
) {
72+
headline = 'Please restart the server';
73+
message =
74+
'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.';
75+
}
76+
77+
this.#peekError(headline, message, error.errors ?? error.detail);
78+
} catch (e) {
79+
// Ignore JSON parse error
80+
console.error('[Interceptor] Caught a 500 Error, but failed parsing error body (expected JSON)', e);
81+
}
7682
}
7783

7884
// Return original response

0 commit comments

Comments
 (0)