From 01a5977350836f14f74ade54b7a402503a22128c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?N=C3=ADcholas=20Oliveira?= Date: Tue, 16 Jul 2024 23:32:03 -0300 Subject: [PATCH] feat: try/catch --- .../src/components/Blocks/PostList.tsx | 52 ++++++++++--------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/projects/wp-nextjs-app/src/components/Blocks/PostList.tsx b/projects/wp-nextjs-app/src/components/Blocks/PostList.tsx index 250ff5987..46f925d89 100644 --- a/projects/wp-nextjs-app/src/components/Blocks/PostList.tsx +++ b/projects/wp-nextjs-app/src/components/Blocks/PostList.tsx @@ -11,30 +11,34 @@ export const PostList: React.FC = async ({ block }) => { const { query } = block.attributes; - const { - data: { posts }, - } = await queryPosts({ - // todo: map the rest of the query object - params: { per_page: query.perPage, postType: query.postType }, - // setting handle error to false will disable automatic handling of errors - // i.e you have to handle the error yourself - handleError: false, - }); + try { + const { + data: { posts }, + } = await queryPosts({ + // todo: map the rest of the query object + params: { per_page: query.perPage, postType: query.postType }, + // setting handle error to false will disable automatic handling of errors + // i.e you have to handle the error yourself + handleError: false, + }); - return ( - <> -

Post List

-
-				{JSON.stringify({ query }, null, 2)}
-			
+ return ( + <> +

Post List

+
+					{JSON.stringify({ query }, null, 2)}
+				
- - - ); + + + ); + } catch (e) { + return 'no posts found'; + } };