Skip to content

Commit

Permalink
PMM-13508 Pass upgrade error messages to UI
Browse files Browse the repository at this point in the history
  • Loading branch information
matejkubinec committed Dec 4, 2024
1 parent a55a663 commit 8a6b42a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
3 changes: 2 additions & 1 deletion ui/src/hooks/api/useUpdates.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<GetUpdatesResponse>
Expand All @@ -36,7 +37,7 @@ export const useCheckUpdates = (
});

export const useStartUpdate = (
options?: UseMutationOptions<StartUpdateResponse, unknown, StartUpdateBody>
options?: UseMutationOptions<StartUpdateResponse, ApiError, StartUpdateBody>
) =>
useMutation({
mutationFn: (args) => startUpdate(args),
Expand Down
6 changes: 4 additions & 2 deletions ui/src/pages/updates/update-card/UpdateCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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',
});
},
Expand Down
4 changes: 4 additions & 0 deletions ui/src/types/api.types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { AxiosError } from 'axios';

export interface ApiErrorResponse {
error: string;
code: number;
message: string;
}

export interface ApiError extends AxiosError<ApiErrorResponse> {}
2 changes: 2 additions & 0 deletions ui/src/utils/textUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const capitalize = (text: string): string =>
text.length ? text[0].toUpperCase() + text.slice(1) : '';

0 comments on commit 8a6b42a

Please sign in to comment.