From dc0ea8a286924ff81dfd21961856c86fe2e7b63b Mon Sep 17 00:00:00 2001 From: MananTank Date: Mon, 11 Nov 2024 18:28:30 +0000 Subject: [PATCH] Catch fetchDeployMetadata error and redirect to 404 (#5380) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Problem solved Short description of the bug fixed or feature added --- ## PR-Codex overview This PR enhances error handling in the `page.tsx` files for the `publish` and `deploy` routes. It introduces checks to call `notFound()` when metadata cannot be fetched, improving user experience by handling cases where the requested data is unavailable. ### Detailed summary - In `apps/dashboard/src/app/(dashboard)/contracts/publish/[publish_uri]/page.tsx`: - Added a check for `publishMetadataFromUri` and called `notFound()` if it is not present. - In `apps/dashboard/src/app/(dashboard)/contracts/deploy/[compiler_uri]/page.tsx`: - Added a check for `metadata` and called `notFound()` if it is not present. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` --- .../(dashboard)/contracts/deploy/[compiler_uri]/page.tsx | 8 +++++++- .../(dashboard)/contracts/publish/[publish_uri]/page.tsx | 6 +++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/apps/dashboard/src/app/(dashboard)/contracts/deploy/[compiler_uri]/page.tsx b/apps/dashboard/src/app/(dashboard)/contracts/deploy/[compiler_uri]/page.tsx index e883caa3435..14e56aef9c0 100644 --- a/apps/dashboard/src/app/(dashboard)/contracts/deploy/[compiler_uri]/page.tsx +++ b/apps/dashboard/src/app/(dashboard)/contracts/deploy/[compiler_uri]/page.tsx @@ -1,4 +1,5 @@ import { getThirdwebClient } from "@/constants/thirdweb.server"; +import { notFound } from "next/navigation"; import { fetchDeployMetadata } from "thirdweb/contract"; import { DeployContractInfo } from "../../../published-contract/components/contract-info"; import { DeployFormForUri } from "../../../published-contract/components/uri-based-deploy"; @@ -16,7 +17,12 @@ export default async function DirectDeployPage(props: DirectDeployPageProps) { client: getThirdwebClient(), // force `ipfs://` prefix uri: parsedUri.startsWith("ipfs://") ? parsedUri : `ipfs://${parsedUri}`, - }); + }).catch(() => null); + + if (!metadata) { + notFound(); + } + return (
null); + + if (!publishMetadataFromUri) { + notFound(); + } let publishMetadata = publishMetadataFromUri;