gdq-archive/frontend/pages/_error.tsx

61 lines
1.8 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

/**
* Copyright (C) 2019-2021 Carl Kittelberger <icedream@icedream.pw>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { NextPage } from 'next';
import { ErrorProps } from 'next/error';
import Head from 'next/head';
import * as React from 'react';
import { useIntl } from 'react-intl';
const Error: NextPage<ErrorProps> = function Error({
statusCode,
title,
}) {
const intl = useIntl();
return (
<div>
<Head>
<title>
{`${title} ${intl.formatMessage({
id: 'App.title',
description: 'The full title of the website',
defaultMessage: 'Games Done Quick Instant Archive',
})}`}
</title>
</Head>
<p>
<h1>
{statusCode}
{' '}
{title}
</h1>
</p>
</div>
);
};
Error.getInitialProps = (ctx) => {
const { res, err } = ctx;
// eslint-disable-next-line no-nested-ternary
const statusCode = res ? res.statusCode : (err ? err.statusCode : 404);
// eslint-disable-next-line no-nested-ternary
const title = res ? res.statusMessage : (err ? err.message : 'Page not found');
return { statusCode, title };
};
export default Error;