mirror of
https://github.com/roleypoly/roleypoly.git
synced 2025-04-24 19:39:11 +00:00
feat(web): add error pages (#193)
This commit is contained in:
parent
f4165f8055
commit
a5f819bc3e
4 changed files with 23 additions and 3 deletions
|
@ -2,6 +2,7 @@ import { Router } from '@reach/router';
|
|||
import { GenericLoadingTemplate } from '@roleypoly/design-system/templates/generic-loading';
|
||||
import * as React from 'react';
|
||||
import AuthLogin from '../pages/auth/login';
|
||||
import ErrorPage from '../pages/error';
|
||||
import LandingPage from '../pages/landing';
|
||||
import PickerPage from '../pages/picker';
|
||||
|
||||
|
@ -18,6 +19,7 @@ const RouteWrapper = (props: {
|
|||
component: React.ComponentType<any>;
|
||||
path?: string;
|
||||
default?: boolean;
|
||||
[x: string]: any;
|
||||
}) => (
|
||||
<React.Suspense fallback={<GenericLoadingTemplate />}>
|
||||
<props.component {...props} />
|
||||
|
@ -31,6 +33,9 @@ export const AppRouter = () => {
|
|||
<RouteWrapper component={ServersPage} path="/servers" />
|
||||
<RouteWrapper component={PickerPage} path="/s/:serverID" />
|
||||
|
||||
<RouteWrapper component={ErrorPage} path="/error" />
|
||||
<RouteWrapper component={ErrorPage} path="/error/:identity" />
|
||||
|
||||
<RouteWrapper
|
||||
component={MachineryNewSession}
|
||||
path="/machinery/new-session/:sessionID"
|
||||
|
@ -42,6 +47,8 @@ export const AppRouter = () => {
|
|||
|
||||
<RouteWrapper component={DevToolsSetApi} path="/x/dev-tools/set-api" />
|
||||
<RouteWrapper component={DevToolsSessionDebug} path="/x/dev-tools/session-debug" />
|
||||
|
||||
<RouteWrapper component={ErrorPage} default identity={404} />
|
||||
</Router>
|
||||
);
|
||||
};
|
||||
|
|
10
packages/web/src/pages/error.tsx
Normal file
10
packages/web/src/pages/error.tsx
Normal file
|
@ -0,0 +1,10 @@
|
|||
import { Error } from '@roleypoly/design-system/templates/errors';
|
||||
import { useAppShellProps } from '../contexts/app-shell/AppShellContext';
|
||||
|
||||
const ErrorPage = (props: { identity: string }) => {
|
||||
const appShellProps = useAppShellProps();
|
||||
|
||||
return <Error code={props.identity} {...appShellProps} />;
|
||||
};
|
||||
|
||||
export default ErrorPage;
|
|
@ -56,8 +56,10 @@ const Picker = (props: PickerProps) => {
|
|||
if (pickerData === false) {
|
||||
if (session && session.user && session.guilds) {
|
||||
const guildSlug = session.guilds.find((guild) => guild.id === props.serverID);
|
||||
|
||||
if (!guildSlug) {
|
||||
throw new Error('placeholder: guild not found in user slugs, 404');
|
||||
console.error({ error: 'guold not in session, 404' });
|
||||
return <Redirect to="/error/404" replace />;
|
||||
}
|
||||
|
||||
return (
|
||||
|
@ -69,7 +71,8 @@ const Picker = (props: PickerProps) => {
|
|||
);
|
||||
}
|
||||
|
||||
throw new Error('placeholder: session state is odd, 404');
|
||||
console.error({ error: 'session state is odd, 404' });
|
||||
return <Redirect to="/error/404" replace />;
|
||||
}
|
||||
|
||||
const onSubmit = async (submittedRoles: string[]) => {
|
||||
|
|
|
@ -9,7 +9,7 @@ const ServersPage = () => {
|
|||
const { isAuthenticated, session } = useSessionContext();
|
||||
const appShellProps = useAppShellProps();
|
||||
if (!isAuthenticated || !session) {
|
||||
return <Redirect to="/" />;
|
||||
return <Redirect to="/" noThrow />;
|
||||
}
|
||||
|
||||
return (
|
||||
|
|
Loading…
Add table
Reference in a new issue