mirror of
https://github.com/chillpadclub/bedolaga-cabinet.git
synced 2026-07-29 18:13:47 +00:00
- getApiErrorMessage now formats Pydantic [{loc, msg}] arrays as readable strings
- LandingPaymentMethod description/icon_url nullable
- Send null instead of empty string for optional payment method fields
20 lines
669 B
TypeScript
20 lines
669 B
TypeScript
import axios from 'axios';
|
|
|
|
export function getApiErrorMessage(err: unknown, fallback: string): string {
|
|
if (axios.isAxiosError(err)) {
|
|
const detail = err.response?.data?.detail;
|
|
if (typeof detail === 'string') return detail;
|
|
// Pydantic V2 validation errors: [{type, loc, msg, input, ctx}]
|
|
if (Array.isArray(detail) && detail.length > 0) {
|
|
return detail
|
|
.map((e: { loc?: (string | number)[]; msg?: string }) => {
|
|
const field = e.loc?.filter((s) => s !== 'body').join('.') ?? '';
|
|
return field ? `${field}: ${e.msg}` : (e.msg ?? '');
|
|
})
|
|
.join('; ');
|
|
}
|
|
return fallback;
|
|
}
|
|
return fallback;
|
|
}
|