Skip to content

Commit

Permalink
GUI error handling POC2b
Browse files Browse the repository at this point in the history
  • Loading branch information
qstokkink committed Sep 12, 2024
1 parent 4c389cc commit 3eeebe0
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
22 changes: 20 additions & 2 deletions src/tribler/ui/src/Router.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { createHashRouter } from "react-router-dom";
import { createHashRouter, Await, useRouteError } from "react-router-dom";
import { Suspense } from 'react';
import { SideLayout } from "./components/layouts/SideLayout";
import { filterActive, filterAll, filterCompleted, filterDownloading, filterInactive } from "./pages/Downloads";
import { handleHTTPError } from "./services/reporting";
import NoMatch from "./pages/NoMatch";
import Dashboard from "./pages/Dashboard";
import Downloads from "./pages/Downloads";
Expand All @@ -20,11 +22,22 @@ import DHT from "./pages/Debug/DHT";
import Libtorrent from "./pages/Debug/Libtorrent";
import Asyncio from "./pages/Debug/Asyncio";

var raiseUnhandledError;
const errorPromise = new Promise(function(resolve, reject){
raiseUnhandledError = reject;
});


function ErrorBoundary() {
handleHTTPError(useRouteError());
return <div>The GUI crashed beyond repair. Please report the error and refresh the page.</div>;
}

export const router = createHashRouter([
{
path: "/",
element: <SideLayout />,
element: <><SideLayout className="h-full" /><Suspense className="hidden invisible">hi<Await resolve={errorPromise}></Await></Suspense></>,
errorElement: <ErrorBoundary />,
children: [
{
path: "",
Expand Down Expand Up @@ -117,3 +130,8 @@ export const router = createHashRouter([
element: <NoMatch />,
},
])

window.addEventListener("unhandledrejection", (event) => {
raiseUnhandledError(event.reason);
event.preventDefault();
});
1 change: 0 additions & 1 deletion src/tribler/ui/src/services/ipv8.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export class IPv8Service {
baseURL: this.baseURL,
withCredentials: true,
});
this.http.interceptors.response.use(function (response) { return response; }, handleHTTPError);
}


Expand Down
2 changes: 1 addition & 1 deletion src/tribler/ui/src/services/reporting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export function handleHTTPError(error: Error | AxiosError) {
if (axios.isAxiosError(error) && error.response?.data?.error?.message){
error_popup_text.textContent = error.response.data.error.message.replace(/(?:\n)/g, '\r\n');
} else {
error_popup_text.textContent = error.message;
error_popup_text.textContent = error.message + "\n" + error.stack.replace(/(?:\n)/g, '\r\n');
}
const error_popup = document.querySelector("#error_popup");
if (error_popup && error_popup.classList.contains("hidden")) {
Expand Down
1 change: 0 additions & 1 deletion src/tribler/ui/src/services/tribler.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export class TriblerService {
baseURL: this.baseURL,
withCredentials: true,
});
this.http.interceptors.response.use(function (response) { return response; }, handleHTTPError);
this.events = new EventSource(this.baseURL + '/events', { withCredentials: true });
this.addEventListener("tribler_exception", OnError);
// Gets the GuiSettings
Expand Down

0 comments on commit 3eeebe0

Please sign in to comment.