Skip to content

Commit 002c545

Browse files
committed
Handle published contract page server side errors (#5098)
## Problem solved Short description of the bug fixed or feature added <!-- start pr-codex --> --- ## PR-Codex overview This PR focuses on improving error handling and null checks in the `published-contract` related components of the dashboard application. It ensures that appropriate actions are taken when data is missing, enhancing the application's robustness. ### Detailed summary - Added null checks for `publishedContracts` in multiple files. - Implemented `notFound()` calls when `publishedContractVersions` or `publishedContracts` are missing. - Enhanced error handling in `getPublishedContractsWithPublisherMapping.ts` with try-catch. - Updated `publisherAddress` resolution logic for better clarity. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
1 parent bc5b543 commit 002c545

File tree

9 files changed

+56
-18
lines changed

9 files changed

+56
-18
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,5 @@ packages/*/typedoc/*
2929
*storybook.log
3030
storybook-static
3131
.aider*
32+
33+
tsconfig.tsbuildinfo

apps/dashboard/src/app/(dashboard)/contracts/publish/[publish_uri]/page.tsx

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { getActiveAccountCookie, getJWTCookie } from "@/constants/cookie";
33
import { getThirdwebClient } from "@/constants/thirdweb.server";
44
import { ContractPublishForm } from "components/contract-components/contract-publish-form";
55
import { revalidatePath } from "next/cache";
6-
import { redirect } from "next/navigation";
6+
import { notFound, redirect } from "next/navigation";
77
import { fetchDeployMetadata } from "thirdweb/contract";
88
import { getPublishedContractsWithPublisherMapping } from "../../../published-contract/[publisher]/[contract_id]/utils/getPublishedContractsWithPublisherMapping";
99

@@ -47,6 +47,10 @@ export default async function PublishContractPage(
4747
contract_id: publishMetadataFromUri.name,
4848
});
4949

50+
if (!publishedContractVersions) {
51+
notFound();
52+
}
53+
5054
const publishedContract = publishedContractVersions[0];
5155

5256
if (publishedContract) {

apps/dashboard/src/app/(dashboard)/published-contract/[publisher]/[contract_id]/[version]/opengraph-image.tsx

+4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ export default async function Image(props: {
2828
fetchPublisherProfile(publisher),
2929
]);
3030

31+
if (!publishedContracts) {
32+
return null;
33+
}
34+
3135
const publishedContract =
3236
publishedContracts.find((p) => p.version === props.params.version) ||
3337
publishedContracts[0];

apps/dashboard/src/app/(dashboard)/published-contract/[publisher]/[contract_id]/[version]/page.tsx

+15-3
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,24 @@ export default async function PublishedContractPage(
2929
props: PublishedContractDeployPageProps,
3030
) {
3131
// resolve ENS if required
32-
const publisherAddress = isAddress(props.params.publisher)
33-
? props.params.publisher
34-
: await resolveAddress({
32+
let publisherAddress: string | undefined = undefined;
33+
34+
if (isAddress(props.params.publisher)) {
35+
publisherAddress = props.params.publisher;
36+
} else {
37+
try {
38+
publisherAddress = await resolveAddress({
3539
client: getThirdwebClient(),
3640
name: mapThirdwebPublisher(props.params.publisher),
3741
});
42+
} catch {
43+
// ignore
44+
}
45+
}
46+
47+
if (!publisherAddress) {
48+
notFound();
49+
}
3850

3951
// get all the published versions of the contract
4052
const publishedContractVersions = await fetchPublishedContractVersions(

apps/dashboard/src/app/(dashboard)/published-contract/[publisher]/[contract_id]/layout.tsx

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { notFound } from "next/navigation";
12
import { PublishedContractBreadcrumbs } from "./components/breadcrumbs.client";
23
import { getPublishedContractsWithPublisherMapping } from "./utils/getPublishedContractsWithPublisherMapping";
34

@@ -23,6 +24,10 @@ export async function generateMetadata({ params }: { params: Params }) {
2324
contract_id: contract_id,
2425
});
2526

27+
if (!publishedContracts) {
28+
notFound();
29+
}
30+
2631
const publishedContract = publishedContracts[0];
2732

2833
if (!publishedContract) {

apps/dashboard/src/app/(dashboard)/published-contract/[publisher]/[contract_id]/opengraph-image.tsx

+4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ export default async function Image(props: {
2727
fetchPublisherProfile(publisher),
2828
]);
2929

30+
if (!publishedContracts) {
31+
return null;
32+
}
33+
3034
const publishedContract = publishedContracts[0];
3135

3236
if (!publishedContract) {

apps/dashboard/src/app/(dashboard)/published-contract/[publisher]/[contract_id]/page.tsx

+4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ export default async function PublishedContractPage(
2222
contract_id: props.params.contract_id,
2323
});
2424

25+
if (!publishedContractVersions) {
26+
notFound();
27+
}
28+
2529
const publishedContract = publishedContractVersions[0];
2630

2731
if (!publishedContract) {

apps/dashboard/src/app/(dashboard)/published-contract/[publisher]/[contract_id]/utils/getPublishedContractsWithPublisherMapping.ts

+17-13
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,23 @@ export async function getPublishedContractsWithPublisherMapping(options: {
1616
}) {
1717
const { publisher, contract_id } = options;
1818

19-
// resolve ENS
20-
const publisherAddress = isAddress(publisher)
21-
? publisher
22-
: await resolveAddress({
23-
client: getThirdwebClient(),
24-
name: mapThirdwebPublisher(publisher),
25-
});
19+
try {
20+
// resolve ENS
21+
const publisherAddress = isAddress(publisher)
22+
? publisher
23+
: await resolveAddress({
24+
client: getThirdwebClient(),
25+
name: mapThirdwebPublisher(publisher),
26+
});
2627

27-
// get all the published versions of the contract
28-
const publishedContractVersions = await fetchPublishedContractVersions(
29-
publisherAddress,
30-
contract_id,
31-
);
28+
// get all the published versions of the contract
29+
const publishedContractVersions = await fetchPublishedContractVersions(
30+
publisherAddress,
31+
contract_id,
32+
);
3233

33-
return publishedContractVersions;
34+
return publishedContractVersions;
35+
} catch {
36+
return undefined;
37+
}
3438
}

apps/dashboard/tsconfig.tsbuildinfo

-1
This file was deleted.

0 commit comments

Comments
 (0)