mirror of
https://github.com/empayre/fleet.git
synced 2024-11-06 00:45:19 +00:00
handle either 403 or 404 on SW details pages (#17017)
Update per https://github.com/fleetdm/fleet/issues/16948#issuecomment-1955239845 --------- Co-authored-by: Jacob Shandling <jacob@fleetdm.com>
This commit is contained in:
parent
6c24f1b447
commit
9d7966ac5f
@ -203,3 +203,10 @@ export const getErrorReason = (
|
||||
|
||||
return "";
|
||||
};
|
||||
|
||||
export const ignoreAxiosError = (err: Error, ignoreStatuses: number[]) => {
|
||||
if (!isAxiosError(err)) {
|
||||
return false;
|
||||
}
|
||||
return !!err.response && ignoreStatuses.includes(err.response.status);
|
||||
};
|
||||
|
@ -4,12 +4,14 @@ import React, { useCallback, useContext } from "react";
|
||||
import { useQuery } from "react-query";
|
||||
import { useErrorHandler } from "react-error-boundary";
|
||||
import { RouteComponentProps } from "react-router";
|
||||
import { AxiosError, isAxiosError } from "axios";
|
||||
import { AxiosError } from "axios";
|
||||
|
||||
import useTeamIdParam from "hooks/useTeamIdParam";
|
||||
|
||||
import { AppContext } from "context/app";
|
||||
|
||||
import { ignoreAxiosError } from "interfaces/errors";
|
||||
|
||||
import osVersionsAPI, {
|
||||
IOSVersionResponse,
|
||||
IGetOsVersionQueryKey,
|
||||
@ -103,9 +105,7 @@ const SoftwareOSDetailsPage = ({
|
||||
enabled: !!osVersionIdFromURL,
|
||||
select: (data) => data.os_version,
|
||||
onError: (error) => {
|
||||
// 403s returned for both non-existent and non-accessable entities
|
||||
// which we intentionally handle with the same empty state for security
|
||||
if (isAxiosError(error) && error.response?.status !== 403) {
|
||||
if (!ignoreAxiosError(error, [403, 404])) {
|
||||
handlePageError(error);
|
||||
}
|
||||
},
|
||||
@ -161,7 +161,6 @@ const SoftwareOSDetailsPage = ({
|
||||
onTeamChange={onTeamChange}
|
||||
/>
|
||||
)}
|
||||
{/* at this point, error can only be 403 per above handling */}
|
||||
{isOsVersionError ? (
|
||||
<DetailsNoHosts
|
||||
header="OS not detected"
|
||||
|
@ -4,13 +4,14 @@ import React, { useCallback, useContext } from "react";
|
||||
import { useQuery } from "react-query";
|
||||
import { useErrorHandler } from "react-error-boundary";
|
||||
import { RouteComponentProps } from "react-router";
|
||||
import { AxiosError, isAxiosError } from "axios";
|
||||
import { AxiosError } from "axios";
|
||||
|
||||
import useTeamIdParam from "hooks/useTeamIdParam";
|
||||
|
||||
import { AppContext } from "context/app";
|
||||
|
||||
import { ISoftwareTitle, formatSoftwareType } from "interfaces/software";
|
||||
import { ignoreAxiosError } from "interfaces/errors";
|
||||
import softwareAPI, {
|
||||
ISoftwareTitleResponse,
|
||||
IGetSoftwareTitleQueryKey,
|
||||
@ -75,9 +76,7 @@ const SoftwareTitleDetailsPage = ({
|
||||
{
|
||||
select: (data) => data.software_title,
|
||||
onError: (error) => {
|
||||
// 403s returned for both non-existent and non-accessable entities
|
||||
// which we intentionally handle with the same empty state for security
|
||||
if (isAxiosError(error) && error.response?.status !== 403) {
|
||||
if (!ignoreAxiosError(error, [403, 404])) {
|
||||
handlePageError(error);
|
||||
}
|
||||
},
|
||||
@ -109,7 +108,6 @@ const SoftwareTitleDetailsPage = ({
|
||||
onTeamChange={onTeamChange}
|
||||
/>
|
||||
)}
|
||||
{/* at this point, error can only be 403 per above handling */}
|
||||
{isSoftwareTitleError ? (
|
||||
<DetailsNoHosts
|
||||
header="Software not detected"
|
||||
|
@ -4,7 +4,7 @@ import React, { useCallback, useContext } from "react";
|
||||
import { useQuery } from "react-query";
|
||||
import { useErrorHandler } from "react-error-boundary";
|
||||
import { RouteComponentProps } from "react-router";
|
||||
import { AxiosError, isAxiosError } from "axios";
|
||||
import { AxiosError } from "axios";
|
||||
|
||||
import useTeamIdParam from "hooks/useTeamIdParam";
|
||||
|
||||
@ -19,6 +19,7 @@ import hostsCountAPI, {
|
||||
IHostsCountResponse,
|
||||
} from "services/entities/host_count";
|
||||
import { ISoftwareVersion, formatSoftwareType } from "interfaces/software";
|
||||
import { ignoreAxiosError } from "interfaces/errors";
|
||||
|
||||
import Spinner from "components/Spinner";
|
||||
import MainContent from "components/MainContent";
|
||||
@ -78,9 +79,7 @@ const SoftwareVersionDetailsPage = ({
|
||||
{
|
||||
select: (data) => data.software,
|
||||
onError: (error) => {
|
||||
// 403s returned for both non-existent and non-accessable entities
|
||||
// which we intentionally handle with the same empty state for security
|
||||
if (isAxiosError(error) && error.response?.status !== 403) {
|
||||
if (!ignoreAxiosError(error, [403, 404])) {
|
||||
handlePageError(error);
|
||||
}
|
||||
},
|
||||
@ -128,7 +127,6 @@ const SoftwareVersionDetailsPage = ({
|
||||
onTeamChange={onTeamChange}
|
||||
/>
|
||||
)}
|
||||
{/* at this point, error can only be 403 per above handling */}
|
||||
{isSoftwareVersionError ? (
|
||||
<DetailsNoHosts
|
||||
header="Software not detected"
|
||||
|
@ -4,7 +4,7 @@ import React, { useCallback, useContext } from "react";
|
||||
import { useQuery } from "react-query";
|
||||
import { useErrorHandler } from "react-error-boundary";
|
||||
import { RouteComponentProps } from "react-router";
|
||||
import { AxiosError, isAxiosError } from "axios";
|
||||
import { AxiosError } from "axios";
|
||||
|
||||
import useTeamIdParam from "hooks/useTeamIdParam";
|
||||
|
||||
@ -15,6 +15,7 @@ import softwareVulnAPI, {
|
||||
IGetVulnerabilityQueryKey,
|
||||
IVulnerabilityResponse,
|
||||
} from "services/entities/vulnerabilities";
|
||||
import { ignoreAxiosError } from "interfaces/errors";
|
||||
|
||||
import Spinner from "components/Spinner";
|
||||
import MainContent from "components/MainContent";
|
||||
@ -80,9 +81,7 @@ const SoftwareVulnerabilityDetailsPage = ({
|
||||
{
|
||||
select: (data) => data.vulnerability,
|
||||
onError: (error) => {
|
||||
// 403s returned for both non-existent and non-accessable entities
|
||||
// which we intentionally handle with the same empty state for security
|
||||
if (isAxiosError(error) && error.response?.status !== 403) {
|
||||
if (!ignoreAxiosError(error, [403, 404])) {
|
||||
handlePageError(error);
|
||||
}
|
||||
},
|
||||
@ -137,7 +136,6 @@ const SoftwareVulnerabilityDetailsPage = ({
|
||||
onTeamChange={onTeamChange}
|
||||
/>
|
||||
)}
|
||||
{/* at this point, error can only be 403 per above handling */}
|
||||
{isVulnError ? (
|
||||
<DetailsNoHosts
|
||||
header="Vulnerability not detected"
|
||||
|
Loading…
Reference in New Issue
Block a user