diff --git a/src/resolution/composite-arns-resolver.ts b/src/resolution/composite-arns-resolver.ts index d7798fa1..0bbe48ad 100644 --- a/src/resolution/composite-arns-resolver.ts +++ b/src/resolution/composite-arns-resolver.ts @@ -49,7 +49,7 @@ export class CompositeArNSResolver implements NameResolver { const cachedResolution: NameResolution = JSON.parse( cachedResolutionBuffer.toString(), ); - resolution = cachedResolution; // hold on tho this in case we need it + resolution = cachedResolution; // hold on to this in case we need it if ( cachedResolution !== undefined && cachedResolution.resolvedAt !== undefined && @@ -71,7 +71,7 @@ export class CompositeArNSResolver implements NameResolver { name, }); const resolution = await resolver.resolve(name); - if (resolution.resolvedId !== undefined) { + if (resolution.resolvedAt !== undefined) { this.cache.set(name, Buffer.from(JSON.stringify(resolution))); this.log.info('Resolved name', { name, resolution }); return resolution; diff --git a/src/resolution/on-demand-arns-resolver.ts b/src/resolution/on-demand-arns-resolver.ts index 7abc2924..c4a589cd 100644 --- a/src/resolution/on-demand-arns-resolver.ts +++ b/src/resolution/on-demand-arns-resolver.ts @@ -67,6 +67,7 @@ export class OnDemandArNSResolver implements NameResolver { }); this.networkProcess = networkProcess; this.ao = ao; + // TODO: use getRecords instead of getArNSRecord this.aoCircuitBreaker = new CircuitBreaker( ({ name }: { name: string }) => { return this.networkProcess.getArNSRecord({ name }); @@ -90,8 +91,21 @@ export class OnDemandArNSResolver implements NameResolver { // find that name in the network process, using the circuit breaker if there are persistent AO issues const arnsRecord = await this.aoCircuitBreaker.fire({ name: baseName }); - if (arnsRecord === undefined || arnsRecord.processId === undefined) { - throw new Error('Invalid name, arns record not found'); + if (arnsRecord === undefined) { + throw new Error('Unexpected undefined from CU'); + } + + if ( + arnsRecord === null || + arnsRecord.processId === undefined + ) { + return { + name, + resolvedId: undefined, + resolvedAt: Date.now(), + ttl: 300, + processId: undefined, + }; } const processId = arnsRecord.processId; diff --git a/src/types.d.ts b/src/types.d.ts index d1181126..f400c52f 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -596,7 +596,17 @@ export interface ValidNameResolution { processId: string; } +// Name resolved, but is missing export interface MissingNameResolution { + name: string; + resolvedId: undefined; + resolvedAt: number; + ttl: number; + processId: undefined; +} + +// An error occured while resolving the name +export interface FailedNameResolution { name: string; resolvedId: undefined; resolvedAt: undefined; @@ -604,7 +614,10 @@ export interface MissingNameResolution { processId: undefined; } -type NameResolution = ValidNameResolution | MissingNameResolution; +type NameResolution = + | ValidNameResolution + | MissingNameResolution + | FailedNameResolution; export interface NameResolver { resolve(name: string): Promise;