From 2c37516f1b2c236ae934da9fa4444aaf1d12c36e Mon Sep 17 00:00:00 2001 From: Marcin Rataj Date: Thu, 4 Feb 2016 22:51:47 +0100 Subject: [PATCH] Do not cache dnslink lookup when API is offline --- lib/api.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/api.js b/lib/api.js index 3dad5d183..a51bb2f6f 100644 --- a/lib/api.js +++ b/lib/api.js @@ -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) @@ -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