Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hot: handle errors from marketplace api #494

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const config: ProcessorConfig = {
cluster: process.env.PUSHER_APP_CLUSTER,
},
marketplaceUrl: process.env.MARKETPLACE_URL || 'https://beta.nft.io',
shouldFetchAccounts: process.env.FETCH_ACCOUNTS !== 'false',
}

export default config
16 changes: 13 additions & 3 deletions src/mappings/util/marketplace.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import axios from 'axios'
import config from '../../config'

const addressesQuery = `query AddressesQuery($ids: [String]) {
const addressesQuery = `query AddressesQuery($ids: [String!]) {
result: AddressesVerification(publicKeys:$ids){
publicKey
username
Expand All @@ -20,7 +20,10 @@ export type AddressVerification = {
}
export async function fetchAccountsDetail(ids: string[]) {
try {
const { data } = await axios.post<{ data: { result: AddressVerification[] } }>(
if (!config.shouldFetchAccounts) {
return ids.map(() => null)
}
const { data } = await axios.post<{ data: { result: AddressVerification[] } } | { errors: any }>(
`${config.marketplaceUrl}/graphql/internal`,
{
query: addressesQuery,
Expand All @@ -29,6 +32,13 @@ export async function fetchAccountsDetail(ids: string[]) {
},
}
)

if ('errors' in data) throw new Error(JSON.stringify(data.errors[0]))
if (!data.data) {
// eslint-disable-next-line no-console
console.error('No data returned', data)
throw new Error('No data returned')
}
return ids.map((id) => {
const account = data.data.result.find((i) => i.publicKey === id)
if (!account) return null
Expand All @@ -41,7 +51,7 @@ export async function fetchAccountsDetail(ids: string[]) {
})
} catch (error) {
// eslint-disable-next-line no-console
console.error('Error: Fetching account details', error)
console.error('Error: Fetching account details', ids, error)
return ids.map(() => null)
}
}
1 change: 1 addition & 0 deletions src/types/custom/processorConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ export interface ProcessorConfig {
redisPort: number
pusher: any
marketplaceUrl: string
shouldFetchAccounts: boolean
}