-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #117 from kieler/116-error-handling-in-management
116 error handling in management
- Loading branch information
Showing
38 changed files
with
1,916 additions
and
1,224 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
import { Spinner } from "@/app/components/spinner"; | ||
|
||
/** | ||
* A loading page to show while the Leaflet map is loaded dynamically. | ||
*/ | ||
export default function LoadMapScreen() { | ||
|
||
return ( | ||
<div className='grid justify-center content-center h-full' > | ||
<div>Loading...</div> | ||
</div> | ||
); | ||
|
||
} | ||
return ( | ||
<div className="flex gap-5 justify-center items-center content-center h-full"> | ||
<Spinner className={"h-10 w-auto"} /> | ||
<div>Loading...</div> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
"use client"; | ||
import { useRouter } from "next/navigation"; | ||
import { PropsWithChildren } from "react"; | ||
|
||
export function ReloadButton({ className, children }: PropsWithChildren<{ className?: string }>) { | ||
const router = useRouter(); | ||
|
||
return ( | ||
<button className={className} onClick={() => router.refresh()}> | ||
{children} | ||
</button> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
export function Spinner({ className }: { className?: string }) { | ||
return ( | ||
<svg className={className} viewBox={"0 0 48 48"}> | ||
<circle | ||
className={"origin-center stroke-6 fill-none stroke-slate-400 dark:stroke-slate-600"} | ||
cx={24} | ||
cy={24} | ||
r={20} | ||
/> | ||
<path | ||
className={ | ||
"motion-safe:animate-spin-ease motion-reduce:animate-pulse origin-center stroke-6 fill-none stroke-slate-900 dark:stroke-slate-100" | ||
} | ||
d={"M 12 40 A 20 20 0 1 1 40 12"} | ||
/> | ||
</svg> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,24 @@ | ||
import BaseLayout from "@/app/components/base_layout" | ||
import {inter, meta_info} from "@/utils/common"; | ||
import {cookies} from "next/headers"; | ||
import {getUsername, inlineTry} from "@/utils/helpers"; | ||
import BaseLayout from "@/app/components/base_layout"; | ||
import { inter, meta_info } from "@/utils/common"; | ||
import { cookies } from "next/headers"; | ||
import { getUsername, inlineTry } from "@/utils/helpers"; | ||
import React from "react"; | ||
|
||
export const metadata = meta_info; | ||
|
||
/** | ||
* The Layout to use on all pages in the app-directory. | ||
* Effectively defers to BaseLayout with minimal adjustments. | ||
*/ | ||
export default function RootLayout({children,}: { children: React.ReactNode }) { | ||
const token = cookies().get('token')?.value; | ||
const username = token ? inlineTry(() => getUsername(token)) : undefined; | ||
export default function RootLayout({ children }: { children: React.ReactNode }) { | ||
const token = cookies().get("token")?.value; | ||
const username = token ? inlineTry(() => getUsername(token)) : undefined; | ||
|
||
return ( | ||
<html lang="en"> | ||
<body className={inter.className}> | ||
<BaseLayout username={username}> | ||
{children} | ||
</BaseLayout> | ||
</body> | ||
</html> | ||
) | ||
return ( | ||
<html lang="en"> | ||
<body className={inter.className}> | ||
<BaseLayout username={username}>{children}</BaseLayout> | ||
</body> | ||
</html> | ||
); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/** display an error message if there is an error */ | ||
export function ErrorMessage({ error }: { error: string | undefined }) { | ||
return ( | ||
<> | ||
{error && ( | ||
<div className="col-span-8 bg-red-300 border-red-600 text-black rounded p-2 text-center"> | ||
Fehler: {error} | ||
</div> | ||
)} | ||
</> | ||
); | ||
} |
44 changes: 44 additions & 0 deletions
44
Website/src/app/management/components/exceptionMessage.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { UnauthorizedError } from "@/utils/types"; | ||
import { ErrorMessage } from "@/app/management/components/errorMessage"; | ||
import Link from "next/link"; | ||
import { ReloadButton } from "@/app/components/reloadButton"; | ||
|
||
/** | ||
* Display a specialized error message for server side exceptions | ||
* @param error The relevant exception thrown. | ||
*/ | ||
export function ExceptionMessage({ error }: { error: unknown }) { | ||
const InternalComponent = () => { | ||
if (error instanceof UnauthorizedError) { | ||
return ( | ||
<> | ||
<div className={"w-full"}> | ||
<ErrorMessage error={"Ihre Anmeldung ist abgelaufen"} /> | ||
</div> | ||
<Link | ||
className={"rounded-full bg-gray-700 px-10 text-white no-a-style w-60 text-center"} | ||
href={"/logout"} | ||
prefetch={false}> | ||
Erneut anmelden | ||
</Link> | ||
</> | ||
); | ||
} else if (error instanceof Error) { | ||
return <ErrorMessage error={error.message} />; | ||
} else if (error instanceof Object) { | ||
return <ErrorMessage error={error.toString()} />; | ||
} else if (typeof error === "string") { | ||
return <ErrorMessage error={error} />; | ||
} | ||
return <ErrorMessage error={"Etwas Unerwartetes ist passiert."} />; | ||
}; | ||
|
||
return ( | ||
<div className={"flex items-center flex-col gap-2"}> | ||
<InternalComponent /> | ||
<ReloadButton className={"rounded-full bg-gray-700 px-10 text-white no-a-style w-60 text-center"}> | ||
Erneut versuchen | ||
</ReloadButton> | ||
</div> | ||
); | ||
} |
Oops, something went wrong.