From 21ae0ea376387273363a2a2c432d81156d7f650e Mon Sep 17 00:00:00 2001 From: Bram Date: Tue, 4 Jun 2024 15:50:08 +0200 Subject: [PATCH] Default to original server name if no well-known found --- src/Internal/Api/Task.elm | 18 ++++++++++++++++-- src/Internal/Config/Text.elm | 7 +++++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/Internal/Api/Task.elm b/src/Internal/Api/Task.elm index 744b1d2..06bb7a3 100644 --- a/src/Internal/Api/Task.elm +++ b/src/Internal/Api/Task.elm @@ -35,9 +35,10 @@ import Internal.Api.Request as Request import Internal.Api.SendMessageEvent.Api import Internal.Api.Versions.Api import Internal.Config.Log exposing (Log, log) +import Internal.Config.Text as Text import Internal.Tools.Json as Json import Internal.Values.Context as Context exposing (APIContext) -import Internal.Values.Envelope exposing (EnvelopeUpdate(..)) +import Internal.Values.Envelope as E exposing (EnvelopeUpdate(..)) import Internal.Values.Room exposing (RoomUpdate(..)) import Internal.Values.Vault exposing (VaultUpdate(..)) import Task @@ -111,7 +112,20 @@ getBaseUrl c = Nothing -> Internal.Api.BaseUrl.Api.baseUrl { url = Context.fromApiFormat c |> .serverName } - c + |> C.catchWith + (\_ -> + let + url : String + url = + Context.fromApiFormat c + |> .serverName + in + { contextChange = Context.setBaseUrl url + , logs = [ log.warn (Text.logs.baseUrlFailed url) ] + , messages = [ E.SetBaseUrl url ] + } + ) + |> (|>) c {-| Get the current timestamp diff --git a/src/Internal/Config/Text.elm b/src/Internal/Config/Text.elm index a63e936..806ac16 100644 --- a/src/Internal/Config/Text.elm +++ b/src/Internal/Config/Text.elm @@ -609,7 +609,8 @@ happened. Most of these unexpected results, are taken account of by the Elm SDK, but logged so that the programmer can do something about it. -} logs : - { baseUrlFound : String -> String -> String + { baseUrlFailed : String -> String + , baseUrlFound : String -> String -> String , getEventId : String -> String , getNow : Int -> String , httpRequest : String -> String -> String @@ -621,7 +622,9 @@ logs : , serverReturnedUnknownJSON : String -> String } logs = - { baseUrlFound = + { baseUrlFailed = + (++) "Failed to find .well-known, using default server address: " + , baseUrlFound = \url baseUrl -> String.concat [ "Found baseURL of ", url, " at address ", baseUrl ] , getEventId = (++) "Received event with id = "