From df0e2896d78fac94303ad303a1a13542a3f3ab6b Mon Sep 17 00:00:00 2001 From: Daniel Moya Date: Thu, 18 Jul 2024 12:13:35 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20empty=20search=20results?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/app/composables/useGoogleBooksAPI.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/modules/app/composables/useGoogleBooksAPI.ts b/src/modules/app/composables/useGoogleBooksAPI.ts index 6cdc74f..1001ce3 100644 --- a/src/modules/app/composables/useGoogleBooksAPI.ts +++ b/src/modules/app/composables/useGoogleBooksAPI.ts @@ -37,7 +37,7 @@ export function useGoogleBooksAPI() { .catch(async (err: Error) => { console.error('🔴 Something went wrong: ', err); throw err; - }); + }) as Promise; } async function searchBooks(searchOptions: GoogleBooksSearchOptions): Promise { @@ -65,11 +65,17 @@ export function useGoogleBooksAPI() { delete searchOptions.q; const searchParams = Object.keys(searchOptions).length - ? `&${new URLSearchParams(searchOptions as Record)}` + ? `&${String(new URLSearchParams(searchOptions as Record))}` : ''; return doCall(`/volumes?q=${query}${searchParams}`) - .then((res: VolumesSearch) => res.items); + .then((res: VolumesSearch) => { + if (res.totalItems) { + return res.items; + } + + return []; + }); } async function getBook(id: string): Promise {