From 766700ffd93ce32aa2a8dd03c67519c564e04238 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Sat, 31 Mar 2018 18:11:34 -0600 Subject: [PATCH] Fix a potential error related to some DNS records --- src/matrix/helpers.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/matrix/helpers.ts b/src/matrix/helpers.ts index 38c9663..0b7f055 100644 --- a/src/matrix/helpers.ts +++ b/src/matrix/helpers.ts @@ -40,6 +40,10 @@ export async function getFederationUrl(serverName: string): Promise { LogService.warn("matrix", "Could not find _matrix._tcp." + serverName + " DNS record. This is normal for most servers."); } + if (!(expirationMs > 0)) { // This is weird so we can catch NaN easier + expirationMs = 4 * 60 * 60 * 1000; + } + if (!serverUrl) serverUrl = "https://" + serverName + ":8448"; LogService.verbose("matrix", "Federation URL for " + serverName + " is " + serverUrl + " - caching for " + expirationMs + " ms"); Cache.for(CACHE_FEDERATION).put(serverName, serverUrl, expirationMs); @@ -47,7 +51,7 @@ export async function getFederationUrl(serverName: string): Promise { } export async function doFederatedApiCall(method: string, serverName: string, endpoint: string, query?: object, body?: object): Promise { - const federationUrl = await getFederationUrl(serverName); + const federationUrl = await getFederationUrl(serverName); LogService.info("matrix", "Doing federated API call: " + federationUrl + endpoint); return new Promise((resolve, reject) => { request({