fix(audit): P2 frontend any→concrete types (181→61), heroicons→lucide-react, missing type exports, toast API, Select options, TaskStatus types; P2-9 hooks.py type annotations

This commit is contained in:
Agent Zero
2026-08-17 22:24:24 +02:00
parent 40fd633917
commit 45ebbee26f
52 changed files with 404 additions and 302 deletions
+45 -8
View File
@@ -9,12 +9,49 @@ export interface CategorizedError {
field?: string;
}
export function categorizeError(error: any): CategorizedError {
const status = error?.status || 0;
if (status === 0) return { category: 'network', status: 0, message: 'Netzwerkfehler', detail: error?.message };
if (status === 401) return { category: 'auth', status, message: 'Nicht authentifiziert', detail: error?.detail };
if (status === 403) return { category: 'permission', status, message: 'Keine Berechtigung', detail: error?.detail };
if (status === 422) return { category: 'validation', status, message: 'Validierungsfehler', detail: error?.detail, field: error?.field };
if (status >= 500) return { category: 'server', status, message: 'Serverfehler', detail: error?.detail };
return { category: 'unknown', status, message: error?.message || 'Unbekannter Fehler', detail: error?.detail };
export interface ErrorLike {
status?: number;
message?: string;
detail?: string;
validationErrors?: Record<string, string[]>;
code?: string;
field?: string;
response?: { data?: { detail?: { detail?: unknown } } };
}
/**
* Narrow an unknown error value to a typed error-like object.
* Handles strings, Error instances, and API error payloads.
*/
export function asError(error: unknown): ErrorLike {
if (typeof error === 'string') {
return { message: error };
}
if (error instanceof Error) {
return { message: error.message };
}
if (error && typeof error === 'object') {
const e = error as Record<string, unknown>;
return {
status: typeof e.status === 'number' ? e.status : undefined,
message: typeof e.message === 'string' ? e.message : undefined,
detail: typeof e.detail === 'string' ? e.detail : undefined,
validationErrors: e.validationErrors as Record<string, string[]> | undefined,
code: typeof e.code === 'string' ? e.code : undefined,
field: typeof e.field === 'string' ? e.field : undefined,
response: e.response as { data?: { detail?: { detail?: unknown } } } | undefined,
};
}
return {};
}
export function categorizeError(error: unknown): CategorizedError {
const e = asError(error);
const status = e.status || 0;
if (status === 0) return { category: 'network', status: 0, message: 'Netzwerkfehler', detail: e.message };
if (status === 401) return { category: 'auth', status, message: 'Nicht authentifiziert', detail: e.detail };
if (status === 403) return { category: 'permission', status, message: 'Keine Berechtigung', detail: e.detail };
if (status === 422) return { category: 'validation', status, message: 'Validierungsfehler', detail: e.detail, field: e.field };
if (status >= 500) return { category: 'server', status, message: 'Serverfehler', detail: e.detail };
return { category: 'unknown', status, message: e.message || 'Unbekannter Fehler', detail: e.detail };
}