Skip to content
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ and this project adheres to
- 🐛(frontend) abort check media status unmount #2194
- ✨(backend) order pinned documents by last updated at #2028

### Changed

- ♿️(frontend) structure correctly 5xx error alerts #2128

## [v4.8.6] - 2026-04-08

### Added
Expand Down
42 changes: 42 additions & 0 deletions src/frontend/apps/e2e/__tests__/app-impress/doc-routing.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,48 @@ test.describe('Doc Routing', () => {
await expect(page).toHaveURL(/\/docs\/$/);
});

test('checks 500 refresh retries original document request', async ({
page,
browserName,
}) => {
const [docTitle] = await createDoc(page, 'doc-routing-500', browserName, 1);
await verifyDocName(page, docTitle);

const docId = page.url().split('/docs/')[1]?.split('/')[0];
// While true, every doc GET fails (including React Query retries) so we
// reliably land on /500. Set to false before refresh so the doc loads again.
let failDocumentGet = true;

await page.route(/\**\/documents\/\**/, async (route) => {
const request = route.request();
if (
failDocumentGet &&
request.method().includes('GET') &&
docId &&
request.url().includes(`/documents/${docId}/`)
) {
Comment thread
Ovgodd marked this conversation as resolved.
await route.fulfill({
status: 500,
json: { detail: 'Internal Server Error' },
});
} else {
await route.continue();
}
});

await page.reload();

await expect(page).toHaveURL(/\/500\/?\?from=/, { timeout: 15000 });

const refreshButton = page.getByRole('button', { name: 'Refresh page' });
await expect(refreshButton).toBeVisible();

failDocumentGet = false;
await refreshButton.click();

await verifyDocName(page, docTitle);
});

test('checks 404 on docs/[id] page', async ({ page }) => {
await page.waitForTimeout(300);

Expand Down
134 changes: 134 additions & 0 deletions src/frontend/apps/impress/src/components/ErrorPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
import { Button } from '@gouvfr-lasuite/cunningham-react';
import Head from 'next/head';
import Image, { StaticImageData } from 'next/image';
import { useTranslation } from 'react-i18next';
import styled from 'styled-components';

import { Box, Icon, StyledLink, Text } from '@/components';

const StyledButton = styled(Button)`
width: fit-content;
`;

interface ErrorPageProps {
image: StaticImageData;
description: string;
refreshTarget?: string;
showReload?: boolean;
}

const getSafeRefreshUrl = (target?: string): string | undefined => {
if (!target) {
return undefined;
}

if (typeof window === 'undefined') {
return target.startsWith('/') && !target.startsWith('//')
? target
: undefined;
}

try {
const url = new URL(target, window.location.origin);
if (url.origin !== window.location.origin) {
return undefined;
}
return url.pathname + url.search + url.hash;
} catch {
Comment thread
coderabbitai[bot] marked this conversation as resolved.
return undefined;
}
};

export const ErrorPage = ({
image,
description,
refreshTarget,
showReload,
}: ErrorPageProps) => {
const { t } = useTranslation();

const errorTitle = t('An unexpected error occurred.');
const safeTarget = getSafeRefreshUrl(refreshTarget);

return (
<>
<Head>
<title>
{errorTitle} - {t('Docs')}
</title>
<meta
property="og:title"
content={`${errorTitle} - ${t('Docs')}`}
key="title"
/>
</Head>
<Box
$align="center"
$margin="auto"
$gap="md"
$padding={{ bottom: '2rem' }}
>
<Text as="h1" $textAlign="center" className="sr-only">
{errorTitle} - {t('Docs')}
</Text>
<Image
src={image}
alt=""
width={300}
style={{
maxWidth: '100%',
height: 'auto',
}}
/>

<Text
as="p"
$textAlign="center"
$maxWidth="350px"
$theme="neutral"
$margin="0"
>
{description}
</Text>

<Box $direction="row" $gap="sm">
<StyledLink href="/">
<StyledButton
color="neutral"
icon={
<Icon
iconName="house"
variant="symbols-outlined"
$withThemeInherited
/>
}
>
{t('Home')}
</StyledButton>
</StyledLink>

{(safeTarget || showReload) && (
<StyledButton
color="neutral"
variant="bordered"
icon={
<Icon
iconName="refresh"
variant="symbols-outlined"
$withThemeInherited
/>
}
onClick={() =>
safeTarget
? window.location.assign(safeTarget)

Check warning

Code scanning / CodeQL

Client-side URL redirect Medium

Untrusted URL redirection depends on a
user-provided value
.
: window.location.reload()
}
>
{t('Refresh page')}
</StyledButton>
)}
</Box>
</Box>
</>
);
};
1 change: 1 addition & 0 deletions src/frontend/apps/impress/src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export * from './Card';
export * from './DropButton';
export * from './dropdown-menu/DropdownMenu';
export * from './Emoji/EmojiPicker';
export * from './ErrorPage';
export * from './quick-search';
export * from './Icon';
export * from './InfiniteScroll';
Expand Down
32 changes: 32 additions & 0 deletions src/frontend/apps/impress/src/pages/500.tsx
Comment thread
Ovgodd marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { useRouter } from 'next/router';
import { ReactElement } from 'react';
import { useTranslation } from 'react-i18next';

import error_img from '@/assets/icons/error-coffee.png';
import { ErrorPage } from '@/components';
import { PageLayout } from '@/layouts';
import { NextPageWithLayout } from '@/types/next';

const Page: NextPageWithLayout = () => {
const { t } = useTranslation();
const { query } = useRouter();
const from = Array.isArray(query.from) ? query.from[0] : query.from;
const refreshTarget =
from?.startsWith('/') && !from.startsWith('//') ? from : undefined;

return (
<ErrorPage
image={error_img}
description={t(
'An unexpected error occurred. Go grab a coffee or try to refresh the page.',
)}
refreshTarget={refreshTarget}
/>
);
};

Page.getLayout = function getLayout(page: ReactElement) {
return <PageLayout withFooter={false}>{page}</PageLayout>;
};

export default Page;
90 changes: 6 additions & 84 deletions src/frontend/apps/impress/src/pages/_error.tsx
Original file line number Diff line number Diff line change
@@ -1,100 +1,22 @@
import { Button } from '@gouvfr-lasuite/cunningham-react';
import * as Sentry from '@sentry/nextjs';
import { NextPageContext } from 'next';
import NextError from 'next/error';
import Head from 'next/head';
import Image from 'next/image';
import { ReactElement } from 'react';
import { useTranslation } from 'react-i18next';
import styled from 'styled-components';

import error_img from '@/assets/icons/error-planetes.png';
import { Box, Icon, StyledLink, Text } from '@/components';
import { ErrorPage } from '@/components';
import { PageLayout } from '@/layouts';

const StyledButton = styled(Button)`
width: fit-content;
`;

const Error = () => {
const { t } = useTranslation();

const errorTitle = t('An unexpected error occurred.');

return (
<>
<Head>
<title>
{errorTitle} - {t('Docs')}
</title>
<meta
property="og:title"
content={`${errorTitle} - ${t('Docs')}`}
key="title"
/>
</Head>
<Box
$align="center"
$margin="auto"
$gap="md"
$padding={{ bottom: '2rem' }}
>
<Text as="h2" $textAlign="center" className="sr-only">
{errorTitle} - {t('Docs')}
</Text>
<Image
src={error_img}
alt=""
width={300}
style={{
maxWidth: '100%',
height: 'auto',
}}
/>

<Text
as="p"
$textAlign="center"
$maxWidth="350px"
$theme="neutral"
$margin="0"
>
{errorTitle}
</Text>

<Box $direction="row" $gap="sm">
<StyledLink href="/">
<StyledButton
color="neutral"
icon={
<Icon
iconName="house"
variant="symbols-outlined"
$withThemeInherited
/>
}
>
{t('Home')}
</StyledButton>
</StyledLink>

<StyledButton
color="neutral"
variant="bordered"
icon={
<Icon
iconName="refresh"
variant="symbols-outlined"
$withThemeInherited
/>
}
onClick={() => window.location.reload()}
>
{t('Refresh page')}
</StyledButton>
</Box>
</Box>
</>
<ErrorPage
image={error_img}
description={t('An unexpected error occurred.')}
showReload
/>
);
};

Expand Down
Loading
Loading