Skip to content

Commit

Permalink
Fix Moments error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
RockerFlower committed Nov 18, 2024
1 parent cef43c9 commit 52a5834
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 23 deletions.
31 changes: 14 additions & 17 deletions app/api/poap-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ export async function getLastMomentsByAuthor({
}: FetchGetLastMomentsByAuthorProps): Promise<Moment[]> {
const poapGraphQLBaseUrl = getEnv({ context }).poapGraphQLBaseUrl;

console.log('poapGraphQLBaseUrl:', poapGraphQLBaseUrl);
console.log('author:', author);

const query = `
query GetLastMomentsByAuthor {
moments(
limit: ${limit},
where: { author: { _eq: "${author}" } },
where: {
author: { _eq: "${author}" },
drop_id: { _is_null: false }
},
order_by: { created_on: desc }
) {
id
Expand Down Expand Up @@ -122,12 +122,18 @@ export async function getLastMomentsByAuthor({
return [];
}

const { data } = await response.json() as GraphQLResponse<GetLastMomentsByAuthorResponse>;
const result = await response.json();

if (result.errors) {
console.error('GraphQL errors:', result.errors);
return [];
}

return data.moments;
const { data } = result as GraphQLResponse<GetLastMomentsByAuthorResponse>;
return data?.moments || [];
} catch (error) {
console.error('Failed to retrieve data:', error);
throw error;
return [];
}
}

Expand Down Expand Up @@ -219,12 +225,6 @@ export async function getCollectionsByDropIds({
}
`;

console.log('poapGraphQLBaseUrl:', poapGraphQLBaseUrl);
console.log('dropIds:', dropIds);
console.log('limit:', limit);
console.log('offset:', offset);
console.log('query:', query);

try {
const response = await fetch(poapGraphQLBaseUrl, {
method: 'POST',
Expand All @@ -241,16 +241,13 @@ export async function getCollectionsByDropIds({
}),
});

console.log('response:', response);
console.log('response.ok:', response.ok);

if (!response.ok) {
console.error(`HTTP error! status: ${response.status}`);
throw new Error(`HTTP error! status: ${response.status}`);
}

const { data } = await response.json() as GraphQLResponse<GetCollectionsByDropIdsResponse>;
console.log('data:', data);

return data.collections;
} catch (error) {
console.error('Failed to retrieve collections:', error);
Expand Down
10 changes: 4 additions & 6 deletions app/routes/v.$address.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Moment, POAP } from "~/types/poap";
import { getPoapsOfAddress } from "~/api/poap";
import { Collection, getCollectionsByDropIds, getLastMomentsByAuthor, getMomentsCountByAuthor } from "~/api/poap-graph";
import { Collection, getLastMomentsByAuthor, getMomentsCountByAuthor } from "~/api/poap-graph";
import { LoaderFunction, MetaFunction, json } from "@remix-run/cloudflare";
import { Link, useLoaderData } from "@remix-run/react";
import { useLoaderData } from "@remix-run/react";
import { cn } from "~/src/cn";
import PoapListItem from "~/components/poap/poap-list-item";
import { Button, Select, SelectItem, Image, Spacer, useDisclosure } from "@nextui-org/react";
import { Button, Select, SelectItem, Spacer, useDisclosure } from "@nextui-org/react";
import AddressInputComponent from "~/components/poap/address-input";
import { getEnv } from "~/src/env";
import FiltersWrapper from "~/components/poap/filters-wrapper";
Expand All @@ -15,7 +15,6 @@ import SidebarDrawer from "~/components/poap/sidebar-drawer";
import { FilterTypeEnum } from "~/types/filter";
import type { Filter } from "app/types/filter";
import { useEffect, useState } from "react";
import { MagicCard } from "~/components/shared/magic-card";
import Marquee from "~/components/shared/marquee";
import { MomentCard } from "~/components/poap/moment-card";
import { CollectionCard } from "~/components/poap/collection-card";
Expand Down Expand Up @@ -101,7 +100,6 @@ export const loader: LoaderFunction = async ({ context, params, request }) => {
if (momentsCount && momentsCount.totalMoments && momentsCount.totalMoments > 0) {
// Get the latest moments
latestMoments = await getLastMomentsByAuthor({ context, author: ethAddress, limit: 10 });
console.log('latestMoments:', latestMoments);
}

// Get the user agent
Expand Down Expand Up @@ -394,7 +392,7 @@ export default function POAPList({ className }: { className?: string }) {
mainWrapper: "max-w-xs",
}}
defaultSelectedKeys={[selectedSort]}
onSelectionChange={(keys) => {
onSelectionChange={(keys: string[]) => {
const selectedKey = Array.from(keys)[0];
if (typeof selectedKey === "string") {
setSelectedSort(selectedKey);
Expand Down

0 comments on commit 52a5834

Please sign in to comment.