Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PMM-13508 Pass upgrade error messages to UI #3357

Open
wants to merge 1 commit into
base: v3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) : '';
Loading