about summary refs log tree commit diff
path: root/LibMatrix/Services/HomeserverProviderService.cs
diff options
context:
space:
mode:
Diffstat (limited to 'LibMatrix/Services/HomeserverProviderService.cs')
-rw-r--r--LibMatrix/Services/HomeserverProviderService.cs38
1 files changed, 25 insertions, 13 deletions
diff --git a/LibMatrix/Services/HomeserverProviderService.cs b/LibMatrix/Services/HomeserverProviderService.cs
index dc4acb1..577a706 100644
--- a/LibMatrix/Services/HomeserverProviderService.cs
+++ b/LibMatrix/Services/HomeserverProviderService.cs
@@ -25,22 +25,34 @@ public class HomeserverProviderService(ILogger<HomeserverProviderService> logger
             }
         }
 
-        // var domain = proxy ?? (await _homeserverResolverService.ResolveHomeserverFromWellKnown(homeserver)).client;
-
         var rhs = await RemoteHomeserver.Create(homeserver, proxy);
-        var clientVersions = await rhs.GetClientVersionsAsync();
+        ClientVersionsResponse clientVersions = new();
+        try {
+            clientVersions = await rhs.GetClientVersionsAsync();
+        }
+        catch (Exception e) {
+            logger.LogError(e, "Failed to get client versions for {homeserver}", homeserver);
+        }
+
         if (proxy is not null)
-            logger.LogInformation($"Homeserver {homeserver} proxied via {proxy}...");
-        logger.LogInformation($"{homeserver}: " + clientVersions.ToJson());
+            logger.LogInformation("Homeserver {homeserver} proxied via {proxy}...", homeserver, proxy);
+        logger.LogInformation("{homeserver}: {clientVersions}", homeserver, clientVersions.ToJson());
 
-        if (clientVersions.UnstableFeatures.TryGetValue("gay.rory.mxapiextensions.v0", out bool a) && a)
-            hs = await AuthenticatedHomeserverGeneric.Create<AuthenticatedHomeserverMxApiExtended>(homeserver, accessToken, proxy);
-        else {
-            var serverVersion = await rhs.GetServerVersionAsync();
-            if (serverVersion is { Server.Name: "Synapse" })
-                hs = await AuthenticatedHomeserverGeneric.Create<AuthenticatedHomeserverSynapse>(homeserver, accessToken, proxy);
-            else
-                hs = await AuthenticatedHomeserverGeneric.Create<AuthenticatedHomeserverGeneric>(homeserver, accessToken, proxy);
+        try {
+            if (clientVersions.UnstableFeatures.TryGetValue("gay.rory.mxapiextensions.v0", out bool a) && a)
+                hs = await AuthenticatedHomeserverGeneric.Create<AuthenticatedHomeserverMxApiExtended>(homeserver, accessToken, proxy);
+            else {
+                var serverVersion = await rhs.GetServerVersionAsync();
+                if (serverVersion is { Server.Name: "Synapse" })
+                    hs = await AuthenticatedHomeserverGeneric.Create<AuthenticatedHomeserverSynapse>(homeserver, accessToken, proxy);
+                else
+                    hs = await AuthenticatedHomeserverGeneric.Create<AuthenticatedHomeserverGeneric>(homeserver, accessToken, proxy);
+            }
+        }
+        catch (Exception e) {
+            logger.LogError(e, "Failed to create authenticated homeserver for {homeserver}", homeserver);
+            sem.Release();
+            throw;
         }
 
         if(impersonatedMxid is not null)