Skip to content

Commit ce81be0

Browse files
author
Ruben van Leeuwen
committed
2143: Handle 500 responses
1 parent ba58772 commit ce81be0

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

frontend/packages/pydantic-forms/src/core/ReactHookForm.tsx

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,31 +23,31 @@ import { useGetConfig } from './hooks';
2323
import { useGetZodSchema } from './hooks';
2424

2525
export interface ReactHookFormProps {
26-
handleSubmit: (fieldValues: FieldValues) => void;
27-
handleCancel: () => void;
28-
pydanticFormSchema?: PydanticFormSchema;
29-
isLoading: boolean;
30-
isFullFilled: boolean;
31-
isSending: boolean;
3226
apiError?: string;
27+
handleCancel: () => void;
28+
handleSubmit: (fieldValues: FieldValues) => void;
3329
hasNext: boolean;
3430
hasPrevious: boolean;
3531
initialValues: FieldValues;
32+
isFullFilled: boolean;
33+
isLoading: boolean;
34+
isSending: boolean;
35+
pydanticFormSchema?: PydanticFormSchema;
3636
title?: string;
3737
}
3838

3939
export const ReactHookForm = ({
40-
handleSubmit,
40+
apiError,
4141
handleCancel,
42-
pydanticFormSchema,
43-
isLoading,
42+
handleSubmit,
43+
hasNext,
44+
hasPrevious,
45+
initialValues,
4446
isFullFilled,
47+
isLoading,
4548
isSending,
46-
apiError,
47-
initialValues,
49+
pydanticFormSchema,
4850
title,
49-
hasNext,
50-
hasPrevious,
5151
}: ReactHookFormProps) => {
5252
const config = useGetConfig();
5353
const t = useTranslations('renderForm');
@@ -56,21 +56,21 @@ export const ReactHookForm = ({
5656
<div>{t('loading')}</div>
5757
);
5858

59-
const ErrorComponent = config.loadingComponent ?? <div>{t('error')}</div>;
59+
const ErrorComponent = config.errorComponent ?? <div>{t('error')}</div>;
6060

6161
const zodSchema = useGetZodSchema(
6262
pydanticFormSchema,
6363
config.componentMatcherExtender,
6464
);
6565

66-
// initialize the react-hook-form
6766
const reactHookForm = useForm({
6867
resolver: zodResolver(zodSchema),
6968
mode: 'all',
7069
values: initialValues,
7170
});
7271

7372
if (apiError) {
73+
console.error('API Error:', apiError);
7474
return ErrorComponent;
7575
}
7676

frontend/packages/pydantic-forms/src/core/hooks/useApiProvider.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export function useApiProvider(
5959
data: request.data,
6060
} as PydanticFormApiResponse;
6161
}
62-
throw new Error('Unknown API Response' + request);
62+
throw new Error('Unknown API Response code');
6363
})
6464
.catch((error) => {
6565
console.error('Error in useSWR api', error);

0 commit comments

Comments
 (0)