From b79a60208187e44252e7610c67dda31ba2cee9b1 Mon Sep 17 00:00:00 2001 From: Burhanuddin Khatri <144617735+BurhanCantCode@users.noreply.github.com> Date: Fri, 2 Aug 2024 21:22:32 +0500 Subject: [PATCH] Update useProducts.ts --- hooks/useProducts.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/hooks/useProducts.ts b/hooks/useProducts.ts index ab39425..4f1458a 100644 --- a/hooks/useProducts.ts +++ b/hooks/useProducts.ts @@ -19,9 +19,9 @@ export const useProducts = () => { const fetchedProducts = await getProducts(user.uid); setProducts(fetchedProducts); setLoading(false); - } catch (err) { + } catch (err: unknown) { console.error('Error fetching products:', err); - setError(`Failed to fetch products: ${err.message}`); + setError(`Failed to fetch products: ${err instanceof Error ? err.message : 'Unknown error'}`); setLoading(false); } }, [user]); @@ -38,10 +38,10 @@ export const useProducts = () => { try { const newProduct = await addProductToFirebase(user.uid, product); setProducts(prevProducts => [...prevProducts, newProduct]); - } catch (err) { + } catch (err: unknown) { console.error('Error adding product:', err); setError('Failed to add product'); - throw err; + throw err instanceof Error ? err : new Error('Failed to add product'); } }; @@ -55,7 +55,7 @@ export const useProducts = () => { setProducts(prevProducts => prevProducts.map(p => p.id === id ? { ...p, quantity } : p) ); - } catch (err) { + } catch (err: unknown) { console.error('Error updating product:', err); setError('Failed to update product'); } @@ -69,11 +69,11 @@ export const useProducts = () => { try { await removeProductFromFirebase(user.uid, id); setProducts(prevProducts => prevProducts.filter(p => p.id !== id)); - } catch (err) { + } catch (err: unknown) { console.error('Error removing product:', err); setError('Failed to remove product'); } }; return { products, loading, error, addProduct, updateProduct, removeProduct, fetchProducts }; -}; \ No newline at end of file +};