Skip to content

Commit

Permalink
return empty array if faulty response
Browse files Browse the repository at this point in the history
  • Loading branch information
karooolis committed Oct 8, 2024
1 parent 1b4cbe7 commit 4ab4902
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ export function WorldsForm({ worlds }: { worlds: Address[] }) {

return (
<div className="mx-auto flex min-h-screen w-[450px] flex-col items-center justify-center p-4">
<h1 className="mb-6 flex items-center gap-4 self-start font-mono text-4xl font-bold uppercase">
<h1 className="flex items-center gap-6 self-start font-mono text-4xl font-bold uppercase">
<Image src={mudLogo} alt="MUD logo" width={48} height={48} /> Worlds Explorer
</h1>

<Command className="overflow-visible">
<Command className="mt-6 overflow-visible bg-transparent">
<Form {...form}>
<form onSubmit={form.handleSubmit(onSubmit)} className="w-full max-w-md space-y-6">
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-6">
<div>
<FormField
control={form.control}
Expand Down
12 changes: 7 additions & 5 deletions packages/explorer/src/app/(explorer)/[chainName]/worlds/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ async function fetchWorlds(chainName: string): Promise<Address[]> {
return [];
}

const response = await fetch(`${blockExplorerUrl}/api/v2/mud/worlds`);
if (!response.ok) {
throw new Error("Failed to fetch worlds");
try {
const response = await fetch(`${blockExplorerUrl}/api/v2/mud/worlds`);
const data: ApiResponse = await response.json();
return data.items.map((world) => world.address.hash);
} catch (error) {
console.error(error);
return [];
}
const data: ApiResponse = await response.json();
return data.items.map((world) => world.address.hash);
}

type Props = {
Expand Down

0 comments on commit 4ab4902

Please sign in to comment.