NORY-26: error page not working (#40)
It still isn't the perfect error handling flow and I will have a look at it again at a later point in time, but for now the typical errors happening are caught and handled correctly.
This commit is contained in:
commit
65f04668f0
4 changed files with 10 additions and 14 deletions
|
@ -31,6 +31,9 @@ bun install
|
||||||
bun run dev
|
bun run dev
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Create an account using the authentication UI on http://localhost:3000.
|
||||||
|
The verification code can be found on the dummy SMTP dashboard on http://localhost:4436.
|
||||||
|
|
||||||
Inside another terminal session we can start the dashboard UI:
|
Inside another terminal session we can start the dashboard UI:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
|
|
@ -51,7 +51,7 @@ export default function Error() {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Card>
|
<Card className="mx-4 md:mx-8 max-w-5xl">
|
||||||
<CardHeader>
|
<CardHeader>
|
||||||
<CardTitle>An error occurred</CardTitle>
|
<CardTitle>An error occurred</CardTitle>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
|
@ -61,7 +61,7 @@ export default function Error() {
|
||||||
</p>
|
</p>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
<Button variant="ghost" asChild>
|
<Button asChild>
|
||||||
<Link href="/" className="inline-flex space-x-2" passHref>
|
<Link href="/" className="inline-flex space-x-2" passHref>
|
||||||
Go back
|
Go back
|
||||||
</Link>
|
</Link>
|
||||||
|
|
|
@ -12,14 +12,13 @@ export async function middleware(request: NextRequest) {
|
||||||
.then((response) => response.data)
|
.then((response) => response.data)
|
||||||
.catch(() => null);
|
.catch(() => null);
|
||||||
|
|
||||||
|
const nodeHost = request.nextUrl.protocol + '//' + request.nextUrl.host;
|
||||||
|
|
||||||
if (!session && !request.nextUrl.pathname.startsWith('/flow')) {
|
if (!session && !request.nextUrl.pathname.startsWith('/flow')) {
|
||||||
|
|
||||||
console.log('NO SESSION');
|
console.log('NO SESSION');
|
||||||
|
|
||||||
const url = request.nextUrl.host +
|
const url = nodeHost + '/flow/login?return_to=' + request.nextUrl.toString();
|
||||||
'/flow/login?return_to=' +
|
|
||||||
request.nextUrl.host +
|
|
||||||
request.nextUrl.pathname;
|
|
||||||
|
|
||||||
console.log('REDIRECT TO', url);
|
console.log('REDIRECT TO', url);
|
||||||
|
|
||||||
|
@ -30,7 +29,7 @@ export async function middleware(request: NextRequest) {
|
||||||
|
|
||||||
console.log('SESSION EXISTS');
|
console.log('SESSION EXISTS');
|
||||||
|
|
||||||
const returnTo = request.nextUrl.searchParams.get('return_to') ?? request.nextUrl.host;
|
const returnTo = request.nextUrl.searchParams.get('return_to') ?? nodeHost;
|
||||||
|
|
||||||
console.log('REDIRECT TO', returnTo);
|
console.log('REDIRECT TO', returnTo);
|
||||||
|
|
||||||
|
@ -41,5 +40,5 @@ export async function middleware(request: NextRequest) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const config = {
|
export const config = {
|
||||||
matcher: '/((?!api|_next/static|_next/image|favicon.png|sitemap.xml|robots.txt|sw.js).*)',
|
matcher: '/((?!api|_next/static|_next/image|favicon.png|sitemap.xml|robots.txt|sw.js|manifest.json|icon-72.png|icon-128.png|icon-144.png|icon-192.png|icon-512.png|mt-logo-orange.png).*)',
|
||||||
};
|
};
|
||||||
|
|
|
@ -18,12 +18,6 @@ export const HandleError = (
|
||||||
return async (
|
return async (
|
||||||
error: AxiosError<any, unknown>,
|
error: AxiosError<any, unknown>,
|
||||||
): Promise<AxiosError | void> => {
|
): Promise<AxiosError | void> => {
|
||||||
if (!error.response || error.response?.status === 0) {
|
|
||||||
window.location.href = `/flow/error?error=${encodeURIComponent(
|
|
||||||
JSON.stringify(error.response),
|
|
||||||
)}`;
|
|
||||||
return Promise.resolve();
|
|
||||||
}
|
|
||||||
|
|
||||||
const responseData = error.response?.data || {};
|
const responseData = error.response?.data || {};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue