Skip to content

Commit 22caecc

Browse files
authored
fix: handle fetcher exception (#181)
1 parent 680a383 commit 22caecc

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

src/adapters/realm-name-validator.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,19 @@ export type IRealmNameComponent = IBaseComponent & {
99
}
1010

1111
export async function createRealmNameComponent(
12-
components: Pick<BaseComponents, 'fetch' | 'config' | 'provider'>
12+
components: Pick<BaseComponents, 'fetch' | 'config' | 'provider' | 'logs'>
1313
): Promise<IRealmNameComponent> {
14-
const { config, fetch, provider } = components
14+
const { config, fetch, provider, logs } = components
1515

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

18+
async function resolveRealmName({ address }: CatalystServerInfo): Promise<string | undefined> {
2219
try {
20+
const response = await fetch.fetch(`${address}/about`)
21+
if (!response.ok) {
22+
return undefined
23+
}
24+
2325
const data: About = await response.json()
2426
return data.configurations.realmName
2527
} catch (err) {
@@ -42,6 +44,7 @@ export async function createRealmNameComponent(
4244
const servers = await getCatalystServersFromDAO(network as any, provider)
4345
const names = new Set(await Promise.all(servers.map(resolveRealmName)))
4446

47+
logger.log(`Realm names found: ${JSON.stringify(Array.from(names))}`)
4548
if (!names.has(realmName)) {
4649
validatedRealmName = realmName
4750
return realmName

src/components.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export async function initComponents(
9191
const ethNetwork = (await config.getString('ETH_NETWORK')) ?? 'mainnet'
9292
const provider = new JsonRpcProvider(`https://rpc.decentraland.org/${encodeURIComponent(ethNetwork)}?project=lamb2`)
9393

94-
const realmName = await createRealmNameComponent({ config, provider, fetch })
94+
const realmName = await createRealmNameComponent({ config, provider, fetch, logs })
9595

9696
return {
9797
config,

0 commit comments

Comments
 (0)