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

Handle error after navigating to deleted scan #1979

Merged
merged 3 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -412,7 +412,7 @@ const PageNotFoundComponent = () => {
</h1>
<div className="mt-6 flex flex-col gap-y-14 items-center">
<h4 className="sm:text-base 2xl:text-xl font-semibold text-text-text-and-icon dark:text-text-text-and-icon flex flex-col text-center">
Page not found.
The page/resource you are looking for does not exist or it has been deleted.
</h4>
<div className="sm:w-[375px] 2xl:w-[455px]">
<SVG404 />
Expand All @@ -439,3 +439,8 @@ export const FourZeroFourPublic = () => {
</div>
);
};

export class DF404Error extends Error {
public readonly status = 404;
public readonly message = 'Resource not found';
}
24 changes: 16 additions & 8 deletions deepfence_frontend/apps/dashboard/src/components/error/500.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useLocation, useRouteError } from 'react-router-dom';
import { cn } from 'tailwind-preset';

import { AppHeader } from '@/components/AppHeader';
import { DF404Error, FourZeroFourAuthenticated } from '@/components/error/404';
import { getSideNavigationState, SideNavigation } from '@/components/SideNavigation';
import { OnboardAppHeader } from '@/features/onboard/components/OnBoardAppHeader';
import storage from '@/utils/storage';
Expand Down Expand Up @@ -53,14 +54,17 @@ export const FiveZeroZero = () => {
const location = useLocation();
const error = useRouteError();
console.error(error);

if (location.pathname.startsWith('/onboard')) {
const errorComponent =
error instanceof DF404Error ? (
<FourZeroFourAuthenticated />
) : (
<ErrorComponent maintenance={((error as Error)?.cause as any)?.status === 503} />
);
return (
<div className="min-h-screen isolate dark:bg-bg-page">
<div className="pt-[56px] h-screen">
<ErrorComponent
maintenance={((error as Error)?.cause as any)?.status === 503}
/>
</div>
<div className="pt-[56px] h-screen">{errorComponent}</div>
<OnboardAppHeader />
</div>
);
Expand All @@ -81,9 +85,13 @@ export const FiveZeroZero = () => {
'ml-[240px]': sideNavExpanded,
})}
>
<ErrorComponent
maintenance={((error as Error)?.cause as any)?.status === 503}
/>
{error instanceof DF404Error ? (
<FourZeroFourAuthenticated />
) : (
<ErrorComponent
maintenance={((error as Error)?.cause as any)?.status === 503}
/>
)}
</main>
</>
) : (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
SearchSearchNodeReq,
SearchSearchScanReq,
} from '@/api/generated';
import { DF404Error } from '@/components/error/404';
import { VulnerabilitiesCountsCardData } from '@/features/vulnerabilities/components/landing/VulnerabilitiesCountsCard';
import { ScanStatusEnum } from '@/types/common';
import { getResponseErrors } from '@/utils/403';
Expand Down Expand Up @@ -339,6 +340,8 @@ export const vulnerabilityQueries = createQueryKeys('vulnerability', {
searchVulnerabilitiesResponse.error,
);
return { message };
} else if (searchVulnerabilitiesResponse.error.response.status === 404) {
throw new DF404Error('Scan not found');
}
throw searchVulnerabilitiesResponse.error;
}
Expand Down Expand Up @@ -523,6 +526,9 @@ export const vulnerabilityQueries = createQueryKeys('vulnerability', {
});

if (!resultVulnerabilityScanResponse.ok) {
if (resultVulnerabilityScanResponse.error.response.status === 404) {
throw new DF404Error('Scan not found');
}
throw resultVulnerabilityScanResponse.error;
}

Expand Down
Loading