Skip to content

Commit

Permalink
fix: sign reported erros only if signed in
Browse files Browse the repository at this point in the history
  • Loading branch information
1emu committed Apr 22, 2024
1 parent 24d993b commit 4d86cf4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/clients/ErrorClient.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Governance } from './Governance'

export class ErrorClient {
public static report(errorMsg: string, extraInfo?: Record<string, unknown>) {
public static async report(errorMsg: string, extraInfo?: Record<string, unknown>, options?: { sign: boolean }) {
try {
Governance.get().reportErrorToServer(errorMsg, extraInfo)
await Governance.get().reportErrorToServer(errorMsg, extraInfo, options)
} catch (e) {
console.error('Error reporting error', e)
}
Expand Down
4 changes: 2 additions & 2 deletions src/clients/Governance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -418,11 +418,11 @@ export class Governance extends API {
})
}

async reportErrorToServer(message: string, extraInfo?: Record<string, unknown>) {
async reportErrorToServer(message: string, extraInfo?: Record<string, unknown>, options = { sign: true }) {
return await this.fetchApiResponse<string>(`/debug/report-error`, {
method: 'POST',
sign: true,
json: { message, extraInfo },
...options,
})
}

Expand Down
22 changes: 16 additions & 6 deletions src/hooks/useGovernanceProfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,38 @@ import isEthereumAddress from 'validator/lib/isEthereumAddress'

import { ErrorClient } from '../clients/ErrorClient'
import { Governance } from '../clients/Governance'
import { useAuthContext } from '../context/AuthProvider.tsx'
import { ErrorCategory } from '../utils/errorCategories'

import { DEFAULT_QUERY_STALE_TIME } from './constants'

export default function useGovernanceProfile(address?: string | null) {
export default function useGovernanceProfile(profileAddress?: string | null) {
const [address] = useAuthContext()
const { data, isLoading: isLoadingGovernanceProfile } = useQuery({
queryKey: [`userGovernanceProfile`, address],
queryKey: [`userGovernanceProfile`, profileAddress],
queryFn: async () => {
if (!address || !isEthereumAddress(address)) return null
if (!profileAddress || !isEthereumAddress(profileAddress)) return null

try {
return await Governance.get().getUserProfile(address)
return await Governance.get().getUserProfile(profileAddress)
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (error: any) {
if (error.statusCode !== 404) {
ErrorClient.report('Error getting governance profile', { error, address, category: ErrorCategory.Profile })
ErrorClient.report(
'Error getting governance profile',
{
error,
address: profileAddress,
category: ErrorCategory.Profile,
},
{ sign: !!address }
)
}
return null
}
},
staleTime: DEFAULT_QUERY_STALE_TIME,
enabled: !!address,
enabled: !!profileAddress,
})

return { profile: data, isProfileValidated: !!data?.forum_id, isLoadingGovernanceProfile }
Expand Down

0 comments on commit 4d86cf4

Please sign in to comment.