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 { extractUmbColorNotification } from './extractUmbColorNotification.function.js' ;
5
+ import { isUmbNotifications } from './isUmbNotifications.function.js' ;
4
6
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api' ;
5
7
import { UmbControllerBase } from '@umbraco-cms/backoffice/class-api' ;
6
8
import { UmbContextConsumerController } from '@umbraco-cms/backoffice/context-api' ;
7
9
import { UMB_NOTIFICATION_CONTEXT , type UmbNotificationOptions } from '@umbraco-cms/backoffice/notification' ;
8
10
import type { UmbDataSourceResponse } from '@umbraco-cms/backoffice/repository' ;
11
+ import type { EventMessageTypeModel } from '@umbraco-cms/backoffice/external/backend-api' ;
12
+
13
+ export interface UmbNotificationsEventModel {
14
+ category : string ;
15
+ message : string ;
16
+ type : EventMessageTypeModel ;
17
+ }
9
18
10
19
export class UmbResourceController extends UmbControllerBase {
11
20
#promise: Promise < any > ;
@@ -128,7 +137,9 @@ export class UmbResourceController extends UmbControllerBase {
128
137
break ;
129
138
default :
130
139
// Other errors
131
- if ( this . #notificationContext) {
140
+ if ( error && error . body && Array . isArray ( error . body ) && isUmbNotifications ( error . body ) ) {
141
+ this . #peekUmbNotifications( error . body ) ;
142
+ } else if ( this . #notificationContext) {
132
143
this . #notificationContext. peek ( 'danger' , {
133
144
data : {
134
145
headline : error . body ?. title ?? error . name ?? 'Server Error' ,
@@ -144,9 +155,21 @@ export class UmbResourceController extends UmbControllerBase {
144
155
}
145
156
}
146
157
158
+ if ( Array . isArray ( data ) && isUmbNotifications ( data ) ) {
159
+ this . #peekUmbNotifications( data ) ;
160
+ }
161
+
147
162
return { data, error } ;
148
163
}
149
164
165
+ #peekUmbNotifications( notifications : Array < UmbNotificationsEventModel > ) {
166
+ notifications . forEach ( ( notification ) => {
167
+ this . #notificationContext?. peek ( extractUmbColorNotification ( notification . type ) , {
168
+ data : { headline : notification . category , message : notification . message } ,
169
+ } ) ;
170
+ } ) ;
171
+ }
172
+
150
173
/**
151
174
* Cancel all resources that are currently being executed by this controller if they are cancelable.
152
175
*
0 commit comments