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