layouts schick gemacht und packagelimits weiter implementiert
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { authorizedFetch } from './auth/tokens';
|
||||
import { ApiError } from './lib/apiError';
|
||||
import { ApiError, emitApiErrorEvent } from './lib/apiError';
|
||||
import type { EventLimitSummary } from './lib/limitWarnings';
|
||||
import i18n from './i18n';
|
||||
|
||||
@@ -338,7 +338,11 @@ type EventSavePayload = {
|
||||
settings?: Record<string, unknown>;
|
||||
};
|
||||
|
||||
async function jsonOrThrow<T>(response: Response, message: string): Promise<T> {
|
||||
type JsonOrThrowOptions = {
|
||||
suppressToast?: boolean;
|
||||
};
|
||||
|
||||
async function jsonOrThrow<T>(response: Response, message: string, options: JsonOrThrowOptions = {}): Promise<T> {
|
||||
if (!response.ok) {
|
||||
const body = await safeJson(response);
|
||||
const status = response.status;
|
||||
@@ -353,6 +357,10 @@ async function jsonOrThrow<T>(response: Response, message: string): Promise<T> {
|
||||
? errorPayload.meta as Record<string, unknown>
|
||||
: undefined;
|
||||
|
||||
if (!options.suppressToast) {
|
||||
emitApiErrorEvent({ message: errorMessage, status, code: errorCode, meta: errorMeta });
|
||||
}
|
||||
|
||||
console.error('[API]', errorMessage, status, body);
|
||||
throw new ApiError(errorMessage, status, errorCode, errorMeta);
|
||||
}
|
||||
@@ -1043,8 +1051,10 @@ export async function getDashboardSummary(): Promise<DashboardSummary | null> {
|
||||
}
|
||||
if (!response.ok) {
|
||||
const payload = await safeJson(response);
|
||||
const fallbackMessage = i18n.t('dashboard:errors.loadFailed', 'Dashboard konnte nicht geladen werden.');
|
||||
emitApiErrorEvent({ message: fallbackMessage, status: response.status });
|
||||
console.error('[API] Failed to load dashboard', response.status, payload);
|
||||
throw new Error('Failed to load dashboard');
|
||||
throw new Error(fallbackMessage);
|
||||
}
|
||||
const json = (await response.json()) as JsonValue;
|
||||
return normalizeDashboard(json);
|
||||
@@ -1057,8 +1067,10 @@ export async function getTenantPackagesOverview(): Promise<{
|
||||
const response = await fetchTenantPackagesEndpoint();
|
||||
if (!response.ok) {
|
||||
const payload = await safeJson(response);
|
||||
const fallbackMessage = i18n.t('common:errors.generic', 'Etwas ist schiefgelaufen. Bitte versuche es erneut.');
|
||||
emitApiErrorEvent({ message: fallbackMessage, status: response.status });
|
||||
console.error('[API] Failed to load tenant packages', response.status, payload);
|
||||
throw new Error('Failed to load tenant packages');
|
||||
throw new Error(fallbackMessage);
|
||||
}
|
||||
const data = (await response.json()) as TenantPackagesResponse;
|
||||
const packages = Array.isArray(data.data) ? data.data.map(normalizeTenantPackage) : [];
|
||||
|
||||
Reference in New Issue
Block a user