Skip to content

Commit

Permalink
Made handleFetch async to await sendStackTrace
Browse files Browse the repository at this point in the history
  • Loading branch information
jarellb committed Nov 7, 2024
1 parent 0dde260 commit 1770cf0
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 11 deletions.
2 changes: 1 addition & 1 deletion ui/src/app/(home)/_components/announcements.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ const Announcements = async () => {
);
};

export default Announcements;
export default Announcements;
10 changes: 10 additions & 0 deletions ui/src/app/ErrorBoundary.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'use client';
import ApiErrorModal from '@/components/modal/api-error-modal';

export default function ErrorBoundary() {
return (
<>
<ApiErrorModal open={true} />
</>
);
}
17 changes: 10 additions & 7 deletions ui/src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import './globals.css';
import { Source_Sans_3 } from 'next/font/google';
import Navbar from '@/components/layout/navbar/navbar';
import Footer from '@/components/layout/footer';
import ErrorBoundary from '@/app/ErrorBoundary';
import type { Metadata } from 'next';

const sourceSans3 = Source_Sans_3({
Expand All @@ -20,13 +21,15 @@ const RootLayout = ({
}: Readonly<{
children?: React.ReactNode;
}>) => (
<html lang="en">
<body className={sourceSans3.variable}>
<Navbar />
<main className="h-full 2xl:min-h-[72.3vh]">{children}</main>
<Footer />
</body>
</html>
<html lang="en">
<body className={sourceSans3.variable}>
<Navbar />
<ErrorBoundary>
<main className="h-full 2xl:min-h-[72.3vh]">{children}</main>
</ErrorBoundary>
<Footer />
</body>
</html>
);

export default RootLayout;
5 changes: 3 additions & 2 deletions ui/src/lib/http-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,11 @@ export const deleteRequestAsync = async <T>(
*
* @returns The res.json()
*/
const handleFetch = (res: Response, httpMethod: HTTPMethod) => {
const handleFetch = async (res: Response, httpMethod: HTTPMethod) => {
if (!res.ok) {
const error = Error(`${res.status} error from ${httpMethod} ${res.url}`);
sendStackTrace(error.stack as string);
await sendStackTrace(error.stack as string);
throw error;
}
return res.json();
};
Expand Down
3 changes: 2 additions & 1 deletion ui/tests/lib/fetchers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ describe('fetchers', () => {
fetchMock.mockResponse(JSON.stringify(mockError), { status: 500 });
let res = ownedGrouping(groupPaths, page, size, sortString, isAscending);
await jest.advanceTimersByTimeAsync(5000);
expect(await res).toEqual(mockError);
expect(await res).toBeInstanceOf(Error);
expect((await res).message).toMatch(/500 error from POST/);

fetchMock.mockReject(() => Promise.reject(mockError));
res = ownedGrouping(groupPaths, page, size, sortString, isAscending);
Expand Down

0 comments on commit 1770cf0

Please sign in to comment.