fix(app): toon API-fout bij opnieuw toewijzen shift in snackbar

Made-with: Cursor
This commit is contained in:
2026-04-12 15:38:46 +02:00
parent 5b173e59c1
commit b2737ba5c8
3 changed files with 59 additions and 24 deletions

View File

@@ -0,0 +1,26 @@
import { isAxiosError } from 'axios'
/**
* Human-readable message from Laravel API validation / exception responses.
*/
export function getApiErrorMessage(error: unknown, fallback: string): string {
if (!isAxiosError(error)) return fallback
const data = error.response?.data as Record<string, unknown> | undefined
if (!data) return fallback
const errors = data.errors
if (errors && typeof errors === 'object' && errors !== null && !Array.isArray(errors)) {
for (const value of Object.values(errors as Record<string, unknown>)) {
if (Array.isArray(value) && value.length > 0 && typeof value[0] === 'string')
return value[0]
if (typeof value === 'string') return value
}
}
const message = data.message
if (typeof message === 'string' && message.trim() !== '') return message
return fallback
}