improve readability of server error for user

This commit is contained in:
Brandon Egger 2023-09-05 19:45:05 -05:00
parent 35c301a686
commit 634f35657e

View File

@ -49,7 +49,20 @@ const EditResourcePage = () => {
setServerError(undefined);
await router.push(`/resources/${data.id}`);
},
onError: (error) => setServerError(error.message),
onError: (error) => {
try {
const zodErrors = JSON.parse(error.message) as unknown as { message: string }[];
setServerError(
zodErrors
.map((error) => {
return error.message;
})
.join(", ")
);
} catch {
setServerError(error.message);
}
},
});
const onSubmit: SubmitHandler<ResourceUpdateInput> = (data) => {