* Extended functionalities
* Added different UIs
This commit is contained in:
@@ -115,10 +115,17 @@ api.interceptors.response.use(
|
||||
);
|
||||
|
||||
/** Extracts a user-facing message from an API error response. */
|
||||
const GENERIC_API_TITLES = new Set([
|
||||
"An unexpected error occurred.",
|
||||
"Internal Server Error",
|
||||
]);
|
||||
|
||||
export function extractApiError(error: unknown, fallback = "Something went wrong."): string {
|
||||
if (axios.isAxiosError(error)) {
|
||||
const data = error.response?.data as { error?: string; title?: string } | undefined;
|
||||
return data?.error ?? data?.title ?? error.message ?? fallback;
|
||||
if (data?.error) return data.error;
|
||||
if (data?.title && !GENERIC_API_TITLES.has(data.title)) return data.title;
|
||||
return fallback;
|
||||
}
|
||||
if (error instanceof Error) {
|
||||
return error.message;
|
||||
|
||||
Reference in New Issue
Block a user