refactor: Remove console logging for error handling in useMarket and useMarketPreloader

- Eliminate console.log and console.warn statements to enhance code clarity and maintainability.
- Replace error logging with comments to silently handle errors during market, stall, and product loading processes.
- Streamline the preloading process by removing unnecessary logging, improving overall code readability.
This commit is contained in:
padreug 2025-08-11 18:21:46 +02:00
parent 786e27ab61
commit 06bcc4b91e
3 changed files with 11 additions and 47 deletions

View file

@ -57,7 +57,6 @@ export function useMarket() {
} catch (err) { } catch (err) {
error.value = err instanceof Error ? err : new Error('Failed to load market') error.value = err instanceof Error ? err : new Error('Failed to load market')
console.error('Error loading market:', err)
throw err throw err
} finally { } finally {
isLoading.value = false isLoading.value = false
@ -115,7 +114,6 @@ export function useMarket() {
} }
} catch (err) { } catch (err) {
console.error('Error loading market data:', err)
// Don't throw error, create default market instead // Don't throw error, create default market instead
const market = { const market = {
d: marketData.identifier, d: marketData.identifier,
@ -141,7 +139,6 @@ export function useMarket() {
// Get the active market to filter by its merchants // Get the active market to filter by its merchants
const activeMarket = marketStore.activeMarket const activeMarket = marketStore.activeMarket
if (!activeMarket) { if (!activeMarket) {
console.warn('No active market found')
return return
} }
@ -191,12 +188,12 @@ export function useMarket() {
marketStore.addStall(stall) marketStore.addStall(stall)
} catch (err) { } catch (err) {
console.warn('Failed to parse stall data:', err) // Silently handle parse errors
} }
}) })
} catch (err) { } catch (err) {
console.error('Error loading stalls:', err) // Silently handle stall loading errors
} }
} }
@ -205,7 +202,6 @@ export function useMarket() {
try { try {
const activeMarket = marketStore.activeMarket const activeMarket = marketStore.activeMarket
if (!activeMarket) { if (!activeMarket) {
console.warn('No active market found')
return return
} }
@ -260,12 +256,12 @@ export function useMarket() {
marketStore.addProduct(product) marketStore.addProduct(product)
} catch (err) { } catch (err) {
console.warn('Failed to parse product data:', err) // Silently handle parse errors
} }
}) })
} catch (err) { } catch (err) {
console.error('Error loading products:', err) // Silently handle product loading errors
} }
} }
@ -314,7 +310,6 @@ export function useMarket() {
try { try {
const activeMarket = marketStore.activeMarket const activeMarket = marketStore.activeMarket
if (!activeMarket) { if (!activeMarket) {
console.warn('No active market found for subscription')
return null return null
} }
@ -334,7 +329,6 @@ export function useMarket() {
return unsubscribe return unsubscribe
} catch (error) { } catch (error) {
console.error('Failed to subscribe to market updates:', error)
return null return null
} }
} }
@ -370,7 +364,6 @@ export function useMarket() {
}) })
if (productsWithoutStalls.length > 0) { if (productsWithoutStalls.length > 0) {
console.log('Found products without stalls:', productsWithoutStalls.length)
// You could create default stalls or handle this as needed // You could create default stalls or handle this as needed
} }
} }
@ -393,7 +386,7 @@ export function useMarket() {
marketStore.addStall(stall) marketStore.addStall(stall)
} }
} catch (err) { } catch (err) {
console.warn('Failed to handle stall event:', err) // Silently handle stall event errors
} }
} }
@ -422,7 +415,7 @@ export function useMarket() {
marketStore.addProduct(product) marketStore.addProduct(product)
} }
} catch (err) { } catch (err) {
console.warn('Failed to handle product data:', err) // Silently handle product event errors
} }
} }
@ -445,23 +438,22 @@ export function useMarket() {
updated_at: event.created_at updated_at: event.created_at
} }
// Note: addOrder method doesn't exist in the store, so we'll just log it // Note: addOrder method doesn't exist in the store, so we'll just handle it silently
console.log('Received order event:', order)
} catch (err) { } catch (err) {
console.warn('Failed to handle order event:', err) // Silently handle order event errors
} }
} }
// Publish a product // Publish a product
const publishProduct = async (_productData: any) => { const publishProduct = async (_productData: any) => {
// Implementation would depend on your event creation logic // Implementation would depend on your event creation logic
console.log('Publishing product:', _productData) // TODO: Implement product publishing
} }
// Publish a stall // Publish a stall
const publishStall = async (_stallData: any) => { const publishStall = async (_stallData: any) => {
// Implementation would depend on your event creation logic // Implementation would depend on your event creation logic
console.log('Publishing stall:', _stallData) // TODO: Implement stall publishing
} }
// Connect to market // Connect to market
@ -494,7 +486,6 @@ export function useMarket() {
} catch (err) { } catch (err) {
error.value = err instanceof Error ? err : new Error('Failed to connect to market') error.value = err instanceof Error ? err : new Error('Failed to connect to market')
console.error('Error connecting to market:', err)
throw err throw err
} }
} }

View file

@ -23,12 +23,9 @@ export function useMarketPreloader() {
const naddr = config.market.defaultNaddr const naddr = config.market.defaultNaddr
if (!naddr) { if (!naddr) {
console.log('No market naddr configured, skipping preload')
return return
} }
console.log('Preloading market data...')
// Connect to market // Connect to market
await market.connectToMarket() await market.connectToMarket()
@ -39,10 +36,8 @@ export function useMarketPreloader() {
marketStore.setError(null) marketStore.setError(null)
isPreloaded.value = true isPreloaded.value = true
console.log('Market data preloaded successfully')
} catch (error) { } catch (error) {
console.error('Failed to preload market:', error)
preloadError.value = error instanceof Error ? error.message : 'Failed to preload market' preloadError.value = error instanceof Error ? error.message : 'Failed to preload market'
// Don't throw error, let the UI handle it gracefully // Don't throw error, let the UI handle it gracefully
} finally { } finally {

View file

@ -127,16 +127,6 @@ const isMarketReady = computed(() => {
const ready = marketPreloader.isPreloaded.value || const ready = marketPreloader.isPreloaded.value ||
(marketStore.products.length > 0 && !isLoading) (marketStore.products.length > 0 && !isLoading)
// Debug logging
console.log('Market ready check:', {
isPreloaded: marketPreloader.isPreloaded.value,
productsLength: marketStore.products.length,
isLoading: isLoading,
isReady: ready,
error: marketStore.error,
preloadError: marketPreloader.preloadError
})
return ready return ready
}) })
@ -147,19 +137,13 @@ const loadMarket = async () => {
throw new Error('No market naddr configured') throw new Error('No market naddr configured')
} }
console.log('Connecting to market...')
await market.connectToMarket() await market.connectToMarket()
console.log('Connected to market')
console.log('Loading market...')
await market.loadMarket(naddr) await market.loadMarket(naddr)
console.log('Market loaded')
// Subscribe to real-time updates // Subscribe to real-time updates
unsubscribe = market.subscribeToMarketUpdates() unsubscribe = market.subscribeToMarketUpdates()
} catch (error) { } catch (error) {
console.error('Failed to load market:', error)
marketStore.setError(error instanceof Error ? error.message : 'Failed to load market') marketStore.setError(error instanceof Error ? error.message : 'Failed to load market')
} }
} }
@ -176,25 +160,19 @@ const addToCart = (product: any) => {
const viewProduct = (product: any) => { const viewProduct = (product: any) => {
// TODO: Navigate to product detail page // TODO: Navigate to product detail page
console.log('View product:', product)
} }
const viewCart = () => { const viewCart = () => {
// TODO: Navigate to cart page // TODO: Navigate to cart page
console.log('View cart')
} }
onMounted(() => { onMounted(() => {
// Only load market if it hasn't been preloaded // Only load market if it hasn't been preloaded
if (needsToLoadMarket.value) { if (needsToLoadMarket.value) {
console.log('Market not preloaded, loading now...')
loadMarket() loadMarket()
} else if (marketPreloader.isPreloaded.value) { } else if (marketPreloader.isPreloaded.value) {
console.log('Market was preloaded, subscribing to updates...')
// Subscribe to real-time updates if market was preloaded // Subscribe to real-time updates if market was preloaded
unsubscribe = market.subscribeToMarketUpdates() unsubscribe = market.subscribeToMarketUpdates()
} else {
console.log('Market data is ready, no additional loading needed')
} }
}) })