mirror of
https://github.com/fleetdm/fleet
synced 2026-05-24 01:18:42 +00:00
Fix unreleased UI bug when parsing API errors for lock and unlock modals (#16867)
This commit is contained in:
parent
f5f9c32cf7
commit
10b1116d70
3 changed files with 10 additions and 14 deletions
|
|
@ -1,12 +1,12 @@
|
|||
import React, { useContext } from "react";
|
||||
|
||||
import { NotificationContext } from "context/notification";
|
||||
import { getErrorReason } from "interfaces/errors";
|
||||
import hostAPI from "services/entities/hosts";
|
||||
|
||||
import Modal from "components/Modal";
|
||||
import Button from "components/buttons/Button";
|
||||
import Checkbox from "components/forms/fields/Checkbox";
|
||||
import { NotificationContext } from "context/notification";
|
||||
import { AxiosError } from "axios";
|
||||
|
||||
const baseClass = "lock-modal";
|
||||
|
||||
|
|
@ -35,9 +35,8 @@ const LockModal = ({
|
|||
await hostAPI.lockHost(id);
|
||||
onSuccess();
|
||||
renderFlash("success", "Host is locking!");
|
||||
} catch (error) {
|
||||
const err = error as AxiosError;
|
||||
renderFlash("error", err.message);
|
||||
} catch (e) {
|
||||
renderFlash("error", getErrorReason(e));
|
||||
}
|
||||
onClose();
|
||||
setIsLocking(false);
|
||||
|
|
|
|||
|
|
@ -1,19 +1,18 @@
|
|||
import React, { useCallback, useContext, useMemo, useState } from "react";
|
||||
import { useQuery } from "react-query";
|
||||
import { AxiosResponse } from "axios";
|
||||
|
||||
import { AppContext } from "context/app";
|
||||
import { NotificationContext } from "context/notification";
|
||||
|
||||
import { IApiError } from "interfaces/errors";
|
||||
import { getErrorReason, IApiError } from "interfaces/errors";
|
||||
import { IHost } from "interfaces/host";
|
||||
import { IHostScript } from "interfaces/script";
|
||||
import { IUser } from "interfaces/user";
|
||||
|
||||
import scriptsAPI, {
|
||||
IHostScriptsQueryKey,
|
||||
IHostScriptsResponse,
|
||||
} from "services/entities/scripts";
|
||||
import { IHostScript } from "interfaces/script";
|
||||
|
||||
import Button from "components/buttons/Button";
|
||||
import DataError from "components/DataError/DataError";
|
||||
|
|
@ -96,9 +95,7 @@ const RunScriptModal = ({
|
|||
);
|
||||
refetchHostScripts();
|
||||
} catch (e) {
|
||||
const error = e as AxiosResponse<IApiError>;
|
||||
console.log(error);
|
||||
renderFlash("error", error.data.errors[0].reason);
|
||||
renderFlash("error", getErrorReason(e));
|
||||
setRunScriptRequested(false);
|
||||
}
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import { AxiosError } from "axios";
|
|||
import { useQuery } from "react-query";
|
||||
|
||||
import { NotificationContext } from "context/notification";
|
||||
import { getErrorReason } from "interfaces/errors";
|
||||
import hostAPI, { IUnlockHostResponse } from "services/entities/hosts";
|
||||
|
||||
import Modal from "components/Modal";
|
||||
|
|
@ -51,9 +52,8 @@ const UnlockModal = ({
|
|||
await hostAPI.unlockHost(id);
|
||||
onSuccess();
|
||||
renderFlash("success", "Host is unlocking!");
|
||||
} catch (error) {
|
||||
const err = error as AxiosError;
|
||||
renderFlash("error", err.message);
|
||||
} catch (e) {
|
||||
renderFlash("error", getErrorReason(e));
|
||||
}
|
||||
onClose();
|
||||
setIsUnlocking(false);
|
||||
|
|
|
|||
Loading…
Reference in a new issue