Skip to content

Commit

Permalink
chore: add 404 to apps
Browse files Browse the repository at this point in the history
  • Loading branch information
im-adithya committed Jan 2, 2024
1 parent fda75ef commit 6922bfe
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
7 changes: 5 additions & 2 deletions frontend/src/hooks/useApp.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import useSWR from "swr";
import { App } from "../types";
import { App, ErrorResponse } from "../types";
import { swrFetcher } from "../swr";

export function useApp(pubkey: string | undefined) {
return useSWR<App>(pubkey && `/api/apps/${pubkey}`, swrFetcher);
return useSWR<App | ErrorResponse>(
pubkey && `/api/apps/${pubkey}`,
swrFetcher
);
}
7 changes: 6 additions & 1 deletion frontend/src/screens/apps/ShowApp.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Loading from "../../components/Loading";
import { useNavigate, useParams } from "react-router-dom";
import { Navigate, useNavigate, useParams } from "react-router-dom";
import { useInfo } from "../../hooks/useInfo";
import { useApp } from "../../hooks/useApp";
import { handleFetchError, validateFetchResponse } from "../../utils/fetch";
Expand All @@ -17,6 +17,11 @@ function ShowApp() {
if (!app || !info) {
return <Loading />;
}

if (app && "error" in app) {
return <Navigate to="/404" />;
}

const handleDelete = async (event: React.FormEvent<HTMLFormElement>) => {
event.preventDefault();
try {
Expand Down
5 changes: 5 additions & 0 deletions frontend/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ export interface User {
expiresAt: string;
}

export interface ErrorResponse {
error: boolean;
message: string;
}

export interface App {
id: number;
userId: number;
Expand Down

0 comments on commit 6922bfe

Please sign in to comment.