mirror of
https://github.com/BrenBroZAYT/gameyfin.git
synced 2026-06-17 08:15:44 +00:00
Fix bug in error handler response handling
Change background of Sonner
This commit is contained in:
@@ -13,7 +13,7 @@ const Toaster = ({ ...props }: ToasterProps) => {
|
|||||||
toastOptions={{
|
toastOptions={{
|
||||||
classNames: {
|
classNames: {
|
||||||
toast:
|
toast:
|
||||||
"group toast group-[.toaster]:bg-background group-[.toaster]:text-foreground group-[.toaster]:border-border group-[.toaster]:shadow-lg",
|
"group toast group-[.toaster]:bg-content1 group-[.toaster]:text-foreground group-[.toaster]:border-border group-[.toaster]:shadow-lg",
|
||||||
description: "group-[.toast]:text-muted-foreground",
|
description: "group-[.toast]:text-muted-foreground",
|
||||||
actionButton:
|
actionButton:
|
||||||
"group-[.toast]:bg-primary group-[.toast]:text-primary-foreground",
|
"group-[.toast]:bg-primary group-[.toast]:text-primary-foreground",
|
||||||
|
|||||||
+2
-1
@@ -11,7 +11,8 @@ import {ErrorHandlingMiddleware} from "Frontend/util/middleware";
|
|||||||
|
|
||||||
export default function App() {
|
export default function App() {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
client.middlewares.push(ErrorHandlingMiddleware);
|
|
||||||
|
client.middlewares = [ErrorHandlingMiddleware];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<NextUIProvider className="size-full" navigate={navigate}>
|
<NextUIProvider className="size-full" navigate={navigate}>
|
||||||
|
|||||||
@@ -2,19 +2,30 @@ import {Middleware, MiddlewareContext, MiddlewareNext} from '@hilla/frontend';
|
|||||||
import {toast} from "sonner";
|
import {toast} from "sonner";
|
||||||
import {getReasonPhrase} from "http-status-codes";
|
import {getReasonPhrase} from "http-status-codes";
|
||||||
|
|
||||||
export const ErrorHandlingMiddleware: Middleware = async function(
|
export const ErrorHandlingMiddleware: Middleware = async function (
|
||||||
context: MiddlewareContext,
|
context: MiddlewareContext,
|
||||||
next: MiddlewareNext
|
next: MiddlewareNext
|
||||||
) {
|
) {
|
||||||
const {endpoint, method} = context;
|
const {endpoint, method} = context;
|
||||||
|
|
||||||
let response: Response = await next(context);
|
let originalResponse = (await next(context));
|
||||||
if(!response.ok) {
|
|
||||||
//Ignore calls to UserEndpoint.getUserInfo since they are managed by Hilla and called on initial load
|
|
||||||
if(endpoint == "UserEndpoint" && method == "getUserInfo") return response;
|
|
||||||
|
|
||||||
|
if (!originalResponse.ok) {
|
||||||
|
// .clone() is necessary because response.json() is one-time only and Hilla accesses it in its internal error handler
|
||||||
|
// @see https://developer.mozilla.org/en-US/docs/Web/API/Response/clone
|
||||||
|
let response: Response = originalResponse.clone();
|
||||||
|
|
||||||
|
//Ignore calls to UserEndpoint.getUserInfo since they are managed by Hilla and called on initial load
|
||||||
|
if (endpoint == "UserEndpoint" && method == "getUserInfo") return originalResponse;
|
||||||
|
|
||||||
|
let json: any = await response.json();
|
||||||
|
|
||||||
|
if (json.type == "dev.hilla.exception.EndpointException") {
|
||||||
|
toast.error(`${getReasonPhrase(response.status)}`, {description: `${json.message}`});
|
||||||
|
} else {
|
||||||
toast.error(`${getReasonPhrase(response.status)}`, {description: `${endpoint}.${method}`})
|
toast.error(`${getReasonPhrase(response.status)}`, {description: `${endpoint}.${method}`})
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return response;
|
return originalResponse;
|
||||||
}
|
}
|
||||||
@@ -94,7 +94,6 @@ function SetupView() {
|
|||||||
initialValues={{username: '', email: '', password: '', passwordRepeat: ''}}
|
initialValues={{username: '', email: '', password: '', passwordRepeat: ''}}
|
||||||
onSubmit={
|
onSubmit={
|
||||||
async (values: any) => {
|
async (values: any) => {
|
||||||
try {
|
|
||||||
await SetupEndpoint.registerSuperAdmin({
|
await SetupEndpoint.registerSuperAdmin({
|
||||||
username: values.username,
|
username: values.username,
|
||||||
password: values.password,
|
password: values.password,
|
||||||
@@ -102,9 +101,6 @@ function SetupView() {
|
|||||||
});
|
});
|
||||||
toast.success("Setup finished", {description: "Have fun with Gameyfin!"});
|
toast.success("Setup finished", {description: "Have fun with Gameyfin!"});
|
||||||
navigate('/login');
|
navigate('/login');
|
||||||
} catch (e) {
|
|
||||||
alert("An error occurred while completing the setup. Please try again.")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
|
|||||||
Reference in New Issue
Block a user