diff --git a/ui/src/hooks/api/useUpdates.tsx b/ui/src/hooks/api/useUpdates.tsx index 04e58593c2..e879b0fe63 100644 --- a/ui/src/hooks/api/useUpdates.tsx +++ b/ui/src/hooks/api/useUpdates.tsx @@ -12,6 +12,7 @@ import { StartUpdateResponse, } from 'types/updates.types'; import { AxiosError } from 'axios'; +import { ApiError } from 'types/api.types'; export const useCheckUpdates = ( options?: UseQueryOptions @@ -36,7 +37,7 @@ export const useCheckUpdates = ( }); export const useStartUpdate = ( - options?: UseMutationOptions + options?: UseMutationOptions ) => useMutation({ mutationFn: (args) => startUpdate(args), diff --git a/ui/src/pages/updates/update-card/UpdateCard.tsx b/ui/src/pages/updates/update-card/UpdateCard.tsx index f38b7c0f08..8775a62d19 100644 --- a/ui/src/pages/updates/update-card/UpdateCard.tsx +++ b/ui/src/pages/updates/update-card/UpdateCard.tsx @@ -23,6 +23,7 @@ import { UpdateInfo } from '../update-info'; import { UpdateInProgressCard } from '../update-in-progress-card'; import { useUpdates } from 'contexts/updates'; import { ChangeLog } from '../change-log'; +import { capitalize } from 'utils/textUtils'; export const UpdateCard: FC = () => { const { inProgress, status, setStatus } = useUpdates(); @@ -41,9 +42,10 @@ export const UpdateCard: FC = () => { setAuthToken(response.authToken); } }, - onError: () => { + onError: (e) => { + const message = e.isAxiosError ? e.response?.data.message : e.message; setStatus(UpdateStatus.Error); - enqueueSnackbar(Messages.error, { + enqueueSnackbar(message ? capitalize(message) : Messages.error, { variant: 'error', }); }, diff --git a/ui/src/types/api.types.ts b/ui/src/types/api.types.ts index db291b8925..4d9c1b5693 100644 --- a/ui/src/types/api.types.ts +++ b/ui/src/types/api.types.ts @@ -1,5 +1,9 @@ +import { AxiosError } from 'axios'; + export interface ApiErrorResponse { error: string; code: number; message: string; } + +export interface ApiError extends AxiosError {} diff --git a/ui/src/utils/textUtils.ts b/ui/src/utils/textUtils.ts new file mode 100644 index 0000000000..47f36b512a --- /dev/null +++ b/ui/src/utils/textUtils.ts @@ -0,0 +1,2 @@ +export const capitalize = (text: string): string => + text.length ? text[0].toUpperCase() + text.slice(1) : '';