feat: add logo field to settings schema and update settings client to handle file uploads
feat: integrate dialog close context in vendor select field and CRUD dialog components feat: enhance vendor general info to format status using utility function feat: implement form dialog context for managing dialog close actions feat: add async select field dialog close context for better form handling fix: update form mutation hook to close dialog on successful submission feat: extend document print types to include expense and credit note feat: add settings update payload type to include logo and other fields feat: create employee attendance and work history pages with resource management feat: implement payment made and received detail pages with actions feat: add quick shortcuts component for easy navigation in the dashboard feat: create actions for payment made and received with print and delete options feat: implement dialog close context for better dialog management feat: add error parsing utility for improved error handling in API responses
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
import { ApiError } from "./client"
|
||||
|
||||
/**
|
||||
* Extract a user-facing error message from a thrown ApiError (or any unknown error).
|
||||
* Order: first Laravel field error → payload.message → error.message → fallback.
|
||||
*/
|
||||
export function parseApiError(error: unknown, fallback = "Request failed"): string {
|
||||
const e = error as { payload?: { errors?: unknown; message?: string }; message?: string } | undefined
|
||||
if (!e) return fallback
|
||||
|
||||
const errors = e.payload?.errors
|
||||
if (errors && typeof errors === "object" && !Array.isArray(errors)) {
|
||||
const first = Object.values(errors as Record<string, unknown>)[0]
|
||||
if (Array.isArray(first) && typeof first[0] === "string") {
|
||||
return first[0]
|
||||
}
|
||||
if (typeof first === "string") {
|
||||
return first
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof e.payload?.message === "string" && e.payload.message.length > 0) {
|
||||
return e.payload.message
|
||||
}
|
||||
|
||||
if (error instanceof ApiError && error.message) {
|
||||
return error.message
|
||||
}
|
||||
|
||||
if (typeof e.message === "string" && e.message.length > 0) {
|
||||
return e.message
|
||||
}
|
||||
|
||||
return fallback
|
||||
}
|
||||
Reference in New Issue
Block a user