mirror of
https://github.com/rommapp/romm.git
synced 2026-11-30 18:42:34 +01:00
14 lines
572 B
TypeScript
14 lines
572 B
TypeScript
// FastAPI puts the useful text in `response.data.detail`; axios' own
|
|
// `message` is a generic "Request failed with status code N".
|
|
import axios from "axios";
|
|
|
|
/** `fallback`, when given, stands in for anything but the server's own detail. */
|
|
export function errorMessage(err: unknown, fallback?: string): string {
|
|
if (axios.isAxiosError(err)) {
|
|
const detail = err.response?.data?.detail;
|
|
if (typeof detail === "string" && detail) return detail;
|
|
return fallback ?? err.message;
|
|
}
|
|
return fallback ?? (err instanceof Error ? err.message : String(err));
|
|
}
|