mirror of
https://github.com/BrenBroZAYT/gameyfin.git
synced 2026-06-15 16:20:03 +00:00
Refine error handling in UI
Implement SystemEndpoint
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
import {Middleware, MiddlewareContext, MiddlewareNext} from '@hilla/frontend';
|
||||
import {toast} from "sonner";
|
||||
import {getReasonPhrase} from "http-status-codes";
|
||||
|
||||
export const ErrorHandlingMiddleware: Middleware = async function(
|
||||
context: MiddlewareContext,
|
||||
next: MiddlewareNext
|
||||
) {
|
||||
const {endpoint, method} = context;
|
||||
|
||||
let response: Response = 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;
|
||||
|
||||
toast.error(`${getReasonPhrase(response.status)}`, {description: `${endpoint}.${method}`})
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
Reference in New Issue
Block a user