Skip to content

Commit

Permalink
fix: handle fetcher exception (#181)
Browse files Browse the repository at this point in the history
  • Loading branch information
hugoArregui authored May 29, 2023
1 parent 680a383 commit 22caecc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
17 changes: 10 additions & 7 deletions src/adapters/realm-name-validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@ export type IRealmNameComponent = IBaseComponent & {
}

export async function createRealmNameComponent(
components: Pick<BaseComponents, 'fetch' | 'config' | 'provider'>
components: Pick<BaseComponents, 'fetch' | 'config' | 'provider' | 'logs'>
): Promise<IRealmNameComponent> {
const { config, fetch, provider } = components
const { config, fetch, provider, logs } = components

async function resolveRealmName({ address }: CatalystServerInfo): Promise<string | undefined> {
const response = await fetch.fetch(`${address}/about`)
if (!response.ok) {
return undefined
}
const logger = logs.getLogger('realm-name')

async function resolveRealmName({ address }: CatalystServerInfo): Promise<string | undefined> {
try {
const response = await fetch.fetch(`${address}/about`)
if (!response.ok) {
return undefined
}

const data: About = await response.json()
return data.configurations.realmName
} catch (err) {
Expand All @@ -42,6 +44,7 @@ export async function createRealmNameComponent(
const servers = await getCatalystServersFromDAO(network as any, provider)
const names = new Set(await Promise.all(servers.map(resolveRealmName)))

logger.log(`Realm names found: ${JSON.stringify(Array.from(names))}`)
if (!names.has(realmName)) {
validatedRealmName = realmName
return realmName
Expand Down
2 changes: 1 addition & 1 deletion src/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export async function initComponents(
const ethNetwork = (await config.getString('ETH_NETWORK')) ?? 'mainnet'
const provider = new JsonRpcProvider(`https://rpc.decentraland.org/${encodeURIComponent(ethNetwork)}?project=lamb2`)

const realmName = await createRealmNameComponent({ config, provider, fetch })
const realmName = await createRealmNameComponent({ config, provider, fetch, logs })

return {
config,
Expand Down

0 comments on commit 22caecc

Please sign in to comment.