Skip to content

Commit f092989

Browse files
authored
Merge pull request #2078 from umbraco/v14/bugfix/show-correct-api-error-description
Bugfix: Show correct msg for ApiError
2 parents abc40e6 + 7b7b18e commit f092989

File tree

3 files changed

+47
-3
lines changed

3 files changed

+47
-3
lines changed

src/packages/core/notification/layouts/default/notification-layout-default.element.ts

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
import { html, LitElement, customElement, property, ifDefined } from '@umbraco-cms/backoffice/external/lit';
1+
import {
2+
html,
3+
LitElement,
4+
customElement,
5+
property,
6+
ifDefined,
7+
nothing,
8+
css,
9+
} from '@umbraco-cms/backoffice/external/lit';
210
import { UmbTextStyles } from '@umbraco-cms/backoffice/style';
311
import type { UmbNotificationDefaultData, UmbNotificationHandler } from '@umbraco-cms/backoffice/notification';
412

@@ -16,11 +24,45 @@ export class UmbNotificationLayoutDefaultElement extends LitElement {
1624
return html`
1725
<uui-toast-notification-layout id="layout" headline="${ifDefined(this.data.headline)}" class="uui-text">
1826
<div id="message">${this.data.message}</div>
27+
${this.#renderStructuredList(this.data.structuredList)}
1928
</uui-toast-notification-layout>
2029
`;
2130
}
2231

23-
static override styles = [UmbTextStyles];
32+
#renderStructuredList(list: unknown) {
33+
if (!this.data.structuredList) return nothing;
34+
if (typeof list !== 'object' || list === null) return nothing;
35+
36+
return html`${Object.entries(list).map(
37+
([property, errors]) =>
38+
html`<div class="structured-list">
39+
<p>${property}:</p>
40+
<ul>
41+
${this.#renderListItem(errors)}
42+
</ul>
43+
</div>`,
44+
)}`;
45+
}
46+
47+
#renderListItem(items: unknown) {
48+
if (Array.isArray(items)) {
49+
return items.map((item) => html`<li>${item}</li>`);
50+
} else {
51+
return html`<li>${items}</li>`;
52+
}
53+
}
54+
55+
static override styles = [
56+
UmbTextStyles,
57+
css`
58+
.structured-list ul {
59+
margin: 0;
60+
}
61+
.structured-list p {
62+
margin: var(--uui-size-3) 0 var(--uui-size-1);
63+
}
64+
`,
65+
];
2466
}
2567

2668
declare global {

src/packages/core/notification/notification.context.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { UmbBasicState } from '@umbraco-cms/backoffice/observable-api';
1212
export interface UmbNotificationDefaultData {
1313
message: string;
1414
headline?: string;
15+
structuredList?: Record<string, Array<unknown>>;
1516
}
1617

1718
/**

src/packages/core/resources/resource.controller.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/* eslint-disable @typescript-eslint/no-explicit-any */
22
import { UMB_AUTH_CONTEXT } from '../auth/index.js';
33
import { isApiError, isCancelError, isCancelablePromise } from './apiTypeValidators.function.js';
4-
import { UMB_NOTIFICATION_CONTEXT, type UmbNotificationOptions } from '@umbraco-cms/backoffice/notification';
54
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
65
import { UmbControllerBase } from '@umbraco-cms/backoffice/class-api';
76
import { UmbContextConsumerController } from '@umbraco-cms/backoffice/context-api';
7+
import { UMB_NOTIFICATION_CONTEXT, type UmbNotificationOptions } from '@umbraco-cms/backoffice/notification';
88
import type { UmbDataSourceResponse } from '@umbraco-cms/backoffice/repository';
99

1010
export class UmbResourceController extends UmbControllerBase {
@@ -133,6 +133,7 @@ export class UmbResourceController extends UmbControllerBase {
133133
data: {
134134
headline: error.body?.title ?? error.name ?? 'Server Error',
135135
message: error.body?.detail ?? error.message ?? 'Something went wrong',
136+
structuredList: error.body.errors,
136137
},
137138
...options,
138139
});

0 commit comments

Comments
 (0)