about summary refs log tree commit diff
path: root/LibMatrix/Services/HomeserverProviderService.cs
diff options
context:
space:
mode:
authorEmma [it/its]@Rory& <root@rory.gay>2024-01-05 12:22:42 +0100
committerEmma [it/its]@Rory& <root@rory.gay>2024-01-05 12:22:42 +0100
commitf215dca816745ef54f5436d6cea9350d6dcd3982 (patch)
tree2749bcd4d1297943478b6080d5688ef642ca1d40 /LibMatrix/Services/HomeserverProviderService.cs
parentToObject and ToJson for MatrixException (diff)
downloadLibMatrix-f215dca816745ef54f5436d6cea9350d6dcd3982.tar.xz
Cleanup
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)