diff --git a/app/soapbox/entity-store/hooks/useCreateEntity.ts b/app/soapbox/entity-store/hooks/useCreateEntity.ts index 6b4aaff73..24ce3af7d 100644 --- a/app/soapbox/entity-store/hooks/useCreateEntity.ts +++ b/app/soapbox/entity-store/hooks/useCreateEntity.ts @@ -1,3 +1,4 @@ +import { AxiosError } from 'axios'; import { z } from 'zod'; import { useAppDispatch, useLoading } from 'soapbox/hooks'; @@ -23,7 +24,7 @@ function useCreateEntity( const [isSubmitting, setPromise] = useLoading(); const { entityType, listKey } = parseEntitiesPath(expandedPath); - async function createEntity(data: Data, callbacks: EntityCallbacks = {}): Promise { + async function createEntity(data: Data, callbacks: EntityCallbacks = {}): Promise { try { const result = await setPromise(entityFn(data)); const schema = opts.schema || z.custom(); @@ -36,8 +37,12 @@ function useCreateEntity( callbacks.onSuccess(entity); } } catch (error) { - if (callbacks.onError) { - callbacks.onError(error); + if (error instanceof AxiosError) { + if (callbacks.onError) { + callbacks.onError(error); + } + } else { + throw error; } } } diff --git a/app/soapbox/features/group/edit-group.tsx b/app/soapbox/features/group/edit-group.tsx index 57f0adfef..7527a1802 100644 --- a/app/soapbox/features/group/edit-group.tsx +++ b/app/soapbox/features/group/edit-group.tsx @@ -62,10 +62,20 @@ const EditGroup: React.FC = ({ params: { id: groupId } }) => { avatar: avatar.file, header: header.file, tags, + }, { + onSuccess() { + toast.success(intl.formatMessage(messages.groupSaved)); + }, + onError(error) { + const message = (error.response?.data as any)?.error; + + if (error.response?.status === 422 && typeof message !== 'undefined') { + toast.error(message); + } + }, }); setIsSubmitting(false); - toast.success(intl.formatMessage(messages.groupSaved)); } const handleAddTag = () => {