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

FD-717 external api errors #1639

Merged
merged 1 commit into from
Sep 24, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,32 @@ import DeviceSearch from './device-search';
import DeviceTable from './device-table';
import WorkflowListModal from './workflow-list-modal';

type UniconfigErrorItem = {
'error-tag': string; // eslint-disable-line @typescript-eslint/naming-convention
'error-info': Record<string, string>; // eslint-disable-line @typescript-eslint/naming-convention
'error-message': string; // eslint-disable-line @typescript-eslint/naming-convention
'error-type': string; // eslint-disable-line @typescript-eslint/naming-convention
};

type UniconfigError = {
code: number;
message: {
errors: {
error: UniconfigErrorItem[];
};
};
};

function parseErrorMessage(msg: string): string {
try {
const parsedError: UniconfigError = JSON.parse(msg);

return parsedError.message.errors.error.map((e) => e['error-message']).join('\n');
} catch (e) {
return 'unknown error';
}
}

const DEVICES_QUERY = gql`
query Devices(
$labels: [String!]
Expand Down Expand Up @@ -352,14 +378,20 @@ const DeviceList: VoidFunctionComponent = () => {
content: 'Device uninstalled successfuly',
});
}
if (res.error) {
addToastNotification({
type: 'error',
title: 'Error',
content: 'Uninstallation failed',
});
if (res.error != null) {
const message = res.error.graphQLErrors.at(0)?.message ?? '';
throw new Error(parseErrorMessage(message));
}
})
.catch((e) => {
addToastNotification({
type: 'error',
title: 'Error',
timeout: 10000,
content: `Uninstallation failed:\n\n
${e}`,
});
})
.finally(() => {
setInstallLoadingMap((m) => {
return {
Expand Down Expand Up @@ -433,14 +465,18 @@ const DeviceList: VoidFunctionComponent = () => {
});
}
if (res.error != null) {
throw new Error(res.error?.message);
const message = parseErrorMessage(res.error.graphQLErrors[0].message);
throw new Error(message);
}
})
.catch(() => {
.catch((e) => {
addToastNotification({
type: 'error',
title: 'Error',
content: 'Installation failed',
timeout: 10,
content: `Installation failed
${e}
`,
});
})
.finally(() => {
Expand Down Expand Up @@ -472,7 +508,8 @@ const DeviceList: VoidFunctionComponent = () => {
})
.then((res) => {
if (res.error != null || res.data == null) {
throw new Error(res.error?.message ?? 'Problem with bulk installation of devices');
const bulkErrors = res.error?.graphQLErrors.map((e) => parseErrorMessage(e.message)) ?? [];
throw new Error(bulkErrors.join('\n'));
}

if (res.data?.deviceInventory.bulkInstallDevices.installedDevices.length === 0) {
Expand All @@ -485,11 +522,13 @@ const DeviceList: VoidFunctionComponent = () => {
content: 'Devices installed successfuly',
});
})
.catch(() => {
.catch((e) => {
addToastNotification({
type: 'error',
title: 'Error',
content: 'Bulk installation of devices has failed',
timeout: 10,
content: `Bulk installation of devices has failed
${e.message}`,
});
})
.finally(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Heading, Flex, keyframes, Icon, Box } from '@chakra-ui/react';
import React, { FC, useState, useEffect, useRef } from 'react';
import FeatherIcon from 'feather-icons-react';

const DEFAULT_TIMEOUT_DISMISS = 3000; // default timeout in which notification will automatically dismiss (ms)\
const DEFAULT_TIMEOUT_DISMISS = 5000; // default timeout in which notification will automatically dismiss (ms)\

const slideIn = keyframes`
from {
Expand Down