From 5c2f2b0684437e1648e0ee3eaa2b6fba762bb3c9 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Wed, 14 Jul 2021 14:19:05 +0100 Subject: [PATCH] Allow well-known to fail, it is optional after all --- src/preview/HomeServer.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/preview/HomeServer.js b/src/preview/HomeServer.js index 3cb91fc..a3ae289 100644 --- a/src/preview/HomeServer.js +++ b/src/preview/HomeServer.js @@ -24,13 +24,17 @@ export async function resolveServer(request, baseURL) { baseURL = `https://${baseURL}`; } { - const {status, body} = await request(`${baseURL}/.well-known/matrix/client`, {method: "GET"}).response(); - if (status === 200) { - const proposedBaseURL = body?.['m.homeserver']?.base_url; - if (typeof proposedBaseURL === "string") { - baseURL = noTrailingSlash(proposedBaseURL); - } - } + try { + const {status, body} = await request(`${baseURL}/.well-known/matrix/client`, {method: "GET"}).response(); + if (status === 200) { + const proposedBaseURL = body?.['m.homeserver']?.base_url; + if (typeof proposedBaseURL === "string") { + baseURL = noTrailingSlash(proposedBaseURL); + } + } + } catch (e) { + console.warn("Failed to fetch ${baseURL}/.well-known/matrix/client", e); + } } { const {status} = await request(`${baseURL}/_matrix/client/versions`, {method: "GET"}).response();