mirror of
https://github.com/chillpadclub/bedolaga-cabinet.git
synced 2026-07-28 17:43:47 +00:00
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:
@@ -30,8 +30,8 @@ export interface LandingTariff {
|
|||||||
export interface LandingPaymentMethod {
|
export interface LandingPaymentMethod {
|
||||||
method_id: string;
|
method_id: string;
|
||||||
display_name: string;
|
display_name: string;
|
||||||
description: string;
|
description: string | null;
|
||||||
icon_url: string;
|
icon_url: string | null;
|
||||||
sort_order: number;
|
sort_order: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -406,7 +406,11 @@ export default function AdminLandingEditor() {
|
|||||||
|
|
||||||
// Strip _id before sending to API
|
// Strip _id before sending to API
|
||||||
const cleanFeatures: AdminLandingFeature[] = features.map(({ _id: _, ...rest }) => rest);
|
const cleanFeatures: AdminLandingFeature[] = features.map(({ _id: _, ...rest }) => rest);
|
||||||
const cleanMethods = paymentMethods.map(({ _id: _, ...rest }) => rest);
|
const cleanMethods = paymentMethods.map(({ _id: _, ...rest }) => ({
|
||||||
|
...rest,
|
||||||
|
description: rest.description || null,
|
||||||
|
icon_url: rest.icon_url || null,
|
||||||
|
}));
|
||||||
|
|
||||||
// Filter out empty period arrays and periods for non-selected tariffs
|
// Filter out empty period arrays and periods for non-selected tariffs
|
||||||
const cleanPeriods = Object.fromEntries(
|
const cleanPeriods = Object.fromEntries(
|
||||||
|
|||||||
@@ -2,7 +2,18 @@ import axios from 'axios';
|
|||||||
|
|
||||||
export function getApiErrorMessage(err: unknown, fallback: string): string {
|
export function getApiErrorMessage(err: unknown, fallback: string): string {
|
||||||
if (axios.isAxiosError(err)) {
|
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;
|
return fallback;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user