Skip to content

Commit

Permalink
error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
melissa-hale committed Jul 18, 2024
1 parent b43172d commit de0340f
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/pages/api/community/getThread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,18 @@ export interface CommunitySlug {
}

export default async (req: NextApiRequest, res: NextApiResponse) => {
if (req.method == "POST") {
const { communitySlug }: CommunitySlug = req.body;
const { communitySlug }: CommunitySlug = req.body;

const { data } = await communityClient.thread({ slug: communitySlug });
try {
const response = await communityClient.thread({ slug: communitySlug });

res.status(200).json(data);
if (!response || !response.data) {
return res.status(400).json({ error: 'Error fetching thread data' });
}

res.status(200).json(response.data);
} catch (error) {
console.error('Error fetching thread data:', error);
res.status(500).json({ error: 'Error fetching thread data' });
}
};

0 comments on commit de0340f

Please sign in to comment.