Skip to content

Commit

Permalink
Do not cache dnslink lookup when API is offline
Browse files Browse the repository at this point in the history
  • Loading branch information
lidel committed Feb 4, 2016
1 parent 0d53002 commit 2c37516
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function isDnslinkPresent (fqdn) {
try {
xhr.send(null)
} catch (e) {
return false
return null
}
if (xhr.status === 200) {
let json = JSON.parse(xhr.responseText)
Expand All @@ -71,9 +71,11 @@ function isDnslinkPresentCached (fqdn) {
let ipfsSupport = dnsCache.get(fqdn)
if (typeof ipfsSupport === 'undefined') {
ipfsSupport = isDnslinkPresent(fqdn)
dnsCache.put(fqdn, ipfsSupport)
if (ipfsSupport !== null) { // dont cache is API was down
dnsCache.put(fqdn, ipfsSupport)
}
}
return ipfsSupport
return !!ipfsSupport
}

exports.apiUrl = apiUrl
Expand Down

0 comments on commit 2c37516

Please sign in to comment.