From 038cc7844156fb49f2f2034150cfa033f54f1f93 Mon Sep 17 00:00:00 2001 From: Avinal Kumar Date: Thu, 8 Sep 2022 11:33:35 +0530 Subject: [PATCH] add better error page Signed-off-by: Avinal Kumar --- src/Main.elm | 10 ++++++---- src/Splash.elm | 31 +++++++++++++++++++++++-------- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/src/Main.elm b/src/Main.elm index 2af30b5..337021f 100644 --- a/src/Main.elm +++ b/src/Main.elm @@ -75,7 +75,8 @@ view model = |> Html.map GotStaticMsg NotFound -> - text "404" + Splash.view (Splash.notFound (Url.toString model.url)) + |> Html.map GotSplashMsg in { title = model.title , body = @@ -201,7 +202,7 @@ toStatic model ( staticModel, cmd ) = init : () -> Url -> Nav.Key -> ( Model, Cmd Msg ) init _ url key = - updateUrl { url = url, page = NotFound, title = "404", key = key } + updateUrl { url = url, page = NotFound, title = "Be My SpaceTime", key = key } @@ -230,7 +231,7 @@ updateUrl : Model -> ( Model, Cmd Msg ) updateUrl model = case Parser.parse parser model.url of Just Splash -> - Splash.init () + Splash.init () False "" |> toSplash model Just Blog -> @@ -246,7 +247,8 @@ updateUrl model = |> toStatic model Nothing -> - ( { model | page = NotFound }, Cmd.none ) + Splash.init () True (Url.toString model.url) + |> toSplash model diff --git a/src/Splash.elm b/src/Splash.elm index 854be33..b29e19b 100644 --- a/src/Splash.elm +++ b/src/Splash.elm @@ -33,6 +33,22 @@ type Msg = Nothing +notFound : String -> Model +notFound error = + { urls = [] + , support_message = "We couldn't find the page you were looking for." + , error_message = "The url " ++ error ++ " does not exist." + } + + +default : Model +default = + { urls = [] + , support_message = "We are looking for the SpaceTime" + , error_message = "We are sorry, but we can't find the SpaceTime" + } + + update : Msg -> Model -> ( Model, Cmd Msg ) update msg model = case msg of @@ -40,11 +56,10 @@ update msg model = ( model, Cmd.none ) -init : () -> ( Model, Cmd Msg ) -init _ = - ( { urls = [] - , support_message = "We are looking for the SpaceTime" - , error_message = "We are sorry, but we can't find the SpaceTime" - } - , Cmd.none - ) +init : () -> Bool -> String -> ( Model, Cmd Msg ) +init _ isError error = + if isError then + ( notFound error, Cmd.none ) + + else + ( default, Cmd.none )