Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Commit

Permalink
fix: dns-json response.Answer may be undefined
Browse files Browse the repository at this point in the history
This fixes an error seen in CI when response.Answer.filter() was called
and we got an error:

  TypeError: Cannot read properties of undefined (reading 'filter')
    at findDNSLinkAnswer (file:///home/runner/work/helia-ipns/helia-ipns/packages/ipns/src/utils/dns.ts:45:34)
    at ipfsPath (file:///home/runner/work/helia-ipns/helia-ipns/packages/ipns/src/utils/dns.ts:29:18)
    at httpQueue.add.signal (file:///home/runner/work/helia-ipns/helia-ipns/packages/ipns/src/dns-resolvers/dns-json-over-https.ts:71:22)
  • Loading branch information
SgtPooki committed Nov 2, 2023
1 parent 9b961ca commit e3764fb
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/ipns/src/utils/dns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export interface DNSResponse {
AD: boolean
CD: boolean
Question: Question[]
Answer: Answer[]
Answer?: Answer[]
}

export const ipfsPath = (domain: string, response: DNSResponse): string => {
Expand All @@ -42,7 +42,7 @@ export const ipfsPath = (domain: string, response: DNSResponse): string => {
}

export const findDNSLinkAnswer = (domain: string, response: DNSResponse): Answer => {
const answer = response.Answer.filter(a => a.data.includes('dnslink=/ipfs') || a.data.includes('dnslink=/ipns')).pop()
const answer = response.Answer?.filter(a => a.data.includes('dnslink=/ipfs') || a.data.includes('dnslink=/ipns')).pop()

if (answer == null) {
throw new CodeError(`No dnslink records found for domain: ${domain}`, 'ERR_DNSLINK_NOT_FOUND')
Expand Down

0 comments on commit e3764fb

Please sign in to comment.