about summary refs log tree commit diff
path: root/LibMatrix/Services
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2026-07-05 22:26:15 +0200
committerRory& <root@rory.gay>2026-07-05 22:26:15 +0200
commitb29c89cdd48ccb7d0094b1115de7876a095b270e (patch)
treeb96081a9b309b0fac8b3f8f8ba92f367e751d85e /LibMatrix/Services
parentHelpers for managing room account data (diff)
downloadLibMatrix-b29c89cdd48ccb7d0094b1115de7876a095b270e.tar.xz
More verbose/typed handling for errors resolving homeservers
Diffstat (limited to 'LibMatrix/Services')
-rw-r--r--LibMatrix/Services/HomeserverResolverService.cs16
1 files changed, 11 insertions, 5 deletions
diff --git a/LibMatrix/Services/HomeserverResolverService.cs b/LibMatrix/Services/HomeserverResolverService.cs

index ed1d2e3..700cfbb 100644 --- a/LibMatrix/Services/HomeserverResolverService.cs +++ b/LibMatrix/Services/HomeserverResolverService.cs
@@ -37,16 +37,22 @@ public class HomeserverResolverService { var res = new WellKnownUris(); if (client != null) - res.Client = (await client)?.TrimEnd('/') ?? throw new Exception($"Could not resolve client URL for {homeserver}."); + res.Client = (await client)?.TrimEnd('/') ?? throw new LibMatrixException() { + ErrorCode = LibMatrixException.ErrorCodes.RLM_NO_CLIENT_URL, + Error = $"Could not resolve client URL for {homeserver}." + }; if (server != null) - res.Server = (await server)?.TrimEnd('/') ?? throw new Exception($"Could not resolve server URL for {homeserver}."); + res.Server = (await server)?.TrimEnd('/') ?? throw new LibMatrixException() { + ErrorCode = LibMatrixException.ErrorCodes.RLM_NO_SERVER_URL, + Error = $"Could not resolve server URL for {homeserver}." + }; _logger.LogInformation("Resolved well-knowns for {hs}: {json}", homeserver, res.ToJson(indent: false)); return res; }); } - + private async Task<T?> GetFromJsonAsync<T>(string url) { try { return await _httpClient.GetFromJsonAsync<T>(url); @@ -56,7 +62,7 @@ public class HomeserverResolverService { return default; } } - + private async Task<string?> _tryResolveClientEndpoint(string homeserver) { ArgumentNullException.ThrowIfNull(homeserver); _logger.LogTrace("Resolving client well-known: {homeserver}", homeserver); @@ -71,7 +77,7 @@ public class HomeserverResolverService { } else if (homeserver.StartsWith("http://")) { clientWellKnown = await GetFromJsonAsync<ClientWellKnown>($"{homeserver}/.well-known/matrix/client"); - + if (clientWellKnown is null && await MatrixHttpClient.CheckSuccessStatus($"{homeserver}/_matrix/client/versions")) return homeserver; }