feat: add forgejo_error_reporter plugin for automatic error reporting to Forgejo issues
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
export type ErrorCategory = 'network' | 'permission' | 'validation' | 'server' | 'auth' | 'unknown';
|
||||
|
||||
export interface CategorizedError {
|
||||
category: ErrorCategory;
|
||||
status: number;
|
||||
message: string;
|
||||
detail?: string;
|
||||
code?: string;
|
||||
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 };
|
||||
}
|
||||
Reference in New Issue
Block a user