Enhance Chat and Market Services with improved error handling and logging

Chat Service:
- Added detailed logging for API calls and responses, including warnings for missing authentication tokens and invalid response formats.
- Implemented a retry mechanism for message subscription setup on connection errors.
- Merged peers instead of clearing existing ones when loading from the API.

Market Service:
- Updated authentication checks to prioritize global auth state, improving user experience during order placement.
- Enhanced error messages for missing Nostr keys to guide users in configuring their profiles.

These changes improve the robustness and user-friendliness of the chat and market functionalities.
This commit is contained in:
padreug 2025-09-06 20:12:41 +02:00
parent 034f3ce80f
commit 8a019db34a
3 changed files with 92 additions and 29 deletions

View file

@ -1,6 +1,7 @@
import { finalizeEvent, type EventTemplate, nip04 } from 'nostr-tools'
import { BaseService } from '@/core/base/BaseService'
import type { Stall, Product, Order } from '@/stores/market'
import { auth } from '@/composables/useAuth'
export interface NostrmarketStall {
id: string
@ -106,15 +107,32 @@ export class NostrmarketService extends BaseService {
}
private getAuth() {
if (!this.authService?.isAuthenticated?.value || !this.authService?.user?.value?.prvkey) {
throw new Error('User not authenticated or private key not available')
// Check global auth first
if (!auth.isAuthenticated.value) {
throw new Error('User not authenticated')
}
// Try to get keys from global auth first, fallback to injected auth service
const globalUser = auth.currentUser.value
const serviceUser = this.authService?.user?.value
const pubkey = this.authService.user.value.pubkey
const prvkey = this.authService.user.value.prvkey
const pubkey = globalUser?.pubkey || serviceUser?.pubkey
const prvkey = globalUser?.prvkey || serviceUser?.prvkey
if (!pubkey || !prvkey) {
throw new Error('Public key or private key is missing')
this.debug('Auth check failed:', {
globalUser: {
exists: !!globalUser,
hasPubkey: !!globalUser?.pubkey,
hasPrvkey: !!globalUser?.prvkey
},
serviceUser: {
exists: !!serviceUser,
hasPubkey: !!serviceUser?.pubkey,
hasPrvkey: !!serviceUser?.prvkey
}
})
throw new Error('Nostr keys not available. Please ensure your Nostr identity is configured in your profile.')
}
// Validate that we have proper hex strings