|
1 | 1 | /* eslint-disable @typescript-eslint/no-explicit-any */
|
2 | 2 | import { UMB_AUTH_CONTEXT } from '../auth/index.js';
|
3 | 3 | import { isApiError, isCancelError, isCancelablePromise } from './apiTypeValidators.function.js';
|
4 |
| -import { html } from '@umbraco-cms/backoffice/external/lit'; |
5 | 4 | import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
|
6 | 5 | import { UmbControllerBase } from '@umbraco-cms/backoffice/class-api';
|
7 | 6 | import { UmbContextConsumerController } from '@umbraco-cms/backoffice/context-api';
|
8 |
| -import { UMB_NOTIFICATION_CONTEXT, type UmbNotificationOptions } from '@umbraco-cms/backoffice/notification'; |
| 7 | +import { |
| 8 | + UMB_NOTIFICATION_CONTEXT, |
| 9 | + type UmbNotificationDefaultData, |
| 10 | + type UmbNotificationOptions, |
| 11 | +} from '@umbraco-cms/backoffice/notification'; |
9 | 12 | import type { UmbDataSourceResponse } from '@umbraco-cms/backoffice/repository';
|
10 | 13 |
|
11 | 14 | export type ErrorMessageText = { property: string; messages: string[] };
|
@@ -39,20 +42,6 @@ export class UmbResourceController extends UmbControllerBase {
|
39 | 42 | this.cancel();
|
40 | 43 | }
|
41 | 44 |
|
42 |
| - #buildApiErrorMessage(error: ErrorMessageText) { |
43 |
| - if (!error) return undefined; |
44 |
| - if (typeof error !== 'object') return undefined; |
45 |
| - |
46 |
| - const entries: Array<ErrorMessageText> = []; |
47 |
| - Object.entries(error).forEach(([property, message]) => { |
48 |
| - entries.push({ property, messages: Array.isArray(message) ? message : [message] }); |
49 |
| - }); |
50 |
| - |
51 |
| - const template = html` ${entries.map((e) => e.messages.map((msg: string) => html`<div>${msg}</div>`))}`; |
52 |
| - |
53 |
| - return template; |
54 |
| - } |
55 |
| - |
56 | 45 | /**
|
57 | 46 | * Base execute function with a try/catch block and return a tuple with the result and the error.
|
58 | 47 | */
|
@@ -146,11 +135,11 @@ export class UmbResourceController extends UmbControllerBase {
|
146 | 135 | default:
|
147 | 136 | // Other errors
|
148 | 137 | if (this.#notificationContext) {
|
149 |
| - const message = this.#buildApiErrorMessage(error?.body?.errors); |
150 | 138 | this.#notificationContext.peek('danger', {
|
151 | 139 | data: {
|
152 | 140 | headline: error.body?.title ?? error.name ?? 'Server Error',
|
153 |
| - message: message ?? error.body?.detail ?? error.message ?? 'Something went wrong', |
| 141 | + message: error.body?.detail ?? error.message ?? 'Something went wrong', |
| 142 | + structuredList: error.body.errors, |
154 | 143 | },
|
155 | 144 | ...options,
|
156 | 145 | });
|
|
0 commit comments