layouts schick gemacht und packagelimits weiter implementiert
This commit is contained in:
@@ -33,3 +33,34 @@ export function getApiErrorMessage(error: unknown, fallback: string): string {
|
||||
|
||||
return fallback;
|
||||
}
|
||||
|
||||
export type ApiErrorEventDetail = {
|
||||
message: string;
|
||||
status?: number;
|
||||
code?: string;
|
||||
meta?: Record<string, unknown>;
|
||||
};
|
||||
|
||||
export const API_ERROR_EVENT = 'admin:api:error';
|
||||
|
||||
export function emitApiErrorEvent(detail: ApiErrorEventDetail): void {
|
||||
if (typeof window === 'undefined') {
|
||||
return;
|
||||
}
|
||||
|
||||
window.dispatchEvent(new CustomEvent<ApiErrorEventDetail>(API_ERROR_EVENT, { detail }));
|
||||
}
|
||||
|
||||
export function registerApiErrorListener(handler: (detail: ApiErrorEventDetail) => void): () => void {
|
||||
if (typeof window === 'undefined') {
|
||||
return () => {};
|
||||
}
|
||||
|
||||
const listener = (event: Event) => {
|
||||
const customEvent = event as CustomEvent<ApiErrorEventDetail>;
|
||||
handler(customEvent.detail);
|
||||
};
|
||||
|
||||
window.addEventListener(API_ERROR_EVENT, listener as EventListener);
|
||||
return () => window.removeEventListener(API_ERROR_EVENT, listener as EventListener);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user