fix: handle Pydantic validation errors in notify + nullify empty optional fields

- 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
This commit is contained in:
Fringg
2026-03-06 18:03:27 +03:00
parent 6755c1dc45
commit 9bd58cb914
3 changed files with 19 additions and 4 deletions

View File

@@ -2,7 +2,18 @@ import axios from 'axios';
export function getApiErrorMessage(err: unknown, fallback: string): string {
if (axios.isAxiosError(err)) {
return err.response?.data?.detail ?? fallback;
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;
}