fix(ui): extract meaningful error messages from API responses
Introduces ApiError class in client.ts that parses Spring Boot error bodies to extract human-readable messages (message, error, detail fields). Adds errorMessage() helper used by all toast descriptions instead of raw String(err) which dumped JSON blobs to the user. Affected: all 10 page components that display error toasts. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { useState } from 'react';
|
||||
import { errorMessage } from '../../api/client';
|
||||
import {
|
||||
Alert,
|
||||
AlertDialog,
|
||||
@@ -131,7 +132,7 @@ export function TeamPage() {
|
||||
setInviteRole('viewer');
|
||||
setShowInvite(false);
|
||||
} catch (err) {
|
||||
toast({ title: 'Invite failed', description: String(err), variant: 'error' });
|
||||
toast({ title: 'Invite failed', description: errorMessage(err), variant: 'error' });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,7 +143,7 @@ export function TeamPage() {
|
||||
toast({ title: `Removed ${removeTarget.name}`, variant: 'success' });
|
||||
setRemoveTarget(null);
|
||||
} catch (err) {
|
||||
toast({ title: 'Remove failed', description: String(err), variant: 'error' });
|
||||
toast({ title: 'Remove failed', description: errorMessage(err), variant: 'error' });
|
||||
setRemoveTarget(null);
|
||||
}
|
||||
}
|
||||
@@ -269,7 +270,7 @@ export function TeamPage() {
|
||||
toast({ title: `MFA reset for ${mfaResetTarget.name || mfaResetTarget.email}`, variant: 'success' });
|
||||
setMfaResetTarget(null);
|
||||
} catch (err) {
|
||||
toast({ title: 'Failed to reset MFA', description: String(err), variant: 'error' });
|
||||
toast({ title: 'Failed to reset MFA', description: errorMessage(err), variant: 'error' });
|
||||
}
|
||||
}}
|
||||
loading={resetMfa.isPending}
|
||||
@@ -297,7 +298,7 @@ export function TeamPage() {
|
||||
setPwTarget(null);
|
||||
setPwValue('');
|
||||
} catch (err) {
|
||||
toast({ title: 'Reset failed', description: String(err), variant: 'error' });
|
||||
toast({ title: 'Reset failed', description: errorMessage(err), variant: 'error' });
|
||||
}
|
||||
}}
|
||||
style={{ display: 'flex', flexDirection: 'column', gap: 16 }}
|
||||
|
||||
Reference in New Issue
Block a user