From a4a84abae5f09cb107d8d05dd77c178dfbe01ac5 Mon Sep 17 00:00:00 2001 From: Eike Kettner <eike.kettner@posteo.de> Date: Wed, 10 Mar 2021 22:14:55 +0100 Subject: [PATCH] Show errors from failed register request Also include a `@` in the valid chars for "idents". This allows to use an e-mail address as username. --- .../src/main/scala/docspell/common/Ident.scala | 2 +- .../webapp/src/main/elm/Page/Register/Update.elm | 14 ++++++++++++-- modules/webapp/src/main/elm/Util/Http.elm | 12 +++++++----- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/modules/common/src/main/scala/docspell/common/Ident.scala b/modules/common/src/main/scala/docspell/common/Ident.scala index ded29dc8..3e30d9d4 100644 --- a/modules/common/src/main/scala/docspell/common/Ident.scala +++ b/modules/common/src/main/scala/docspell/common/Ident.scala @@ -26,7 +26,7 @@ object Ident { implicit val identEq: Eq[Ident] = Eq.by(_.id) - val chars: Set[Char] = (('A' to 'Z') ++ ('a' to 'z') ++ ('0' to '9') ++ "-_.").toSet + val chars: Set[Char] = (('A' to 'Z') ++ ('a' to 'z') ++ ('0' to '9') ++ "-_.@").toSet def randomUUID[F[_]: Sync]: F[Ident] = Sync[F].delay(unsafe(UUID.randomUUID.toString)) diff --git a/modules/webapp/src/main/elm/Page/Register/Update.elm b/modules/webapp/src/main/elm/Page/Register/Update.elm index e400bf58..3f6f01bc 100644 --- a/modules/webapp/src/main/elm/Page/Register/Update.elm +++ b/modules/webapp/src/main/elm/Page/Register/Update.elm @@ -1,9 +1,11 @@ module Page.Register.Update exposing (update) import Api +import Api.Model.BasicResult exposing (BasicResult) import Data.Flags exposing (Flags) import Page exposing (Page(..)) import Page.Register.Data exposing (..) +import Util.Http update : Flags -> Msg -> Model -> ( Model, Cmd Msg ) @@ -106,8 +108,16 @@ update flags msg model = , cmd ) - SubmitResp (Err _) -> - ( model, Cmd.none ) + SubmitResp (Err err) -> + let + errMsg = + Util.Http.errorToString err + + res = + BasicResult False + (errMsg ++ " Please check the form and try again.") + in + ( { model | result = Just res }, Cmd.none ) validateForm : Model -> List String diff --git a/modules/webapp/src/main/elm/Util/Http.elm b/modules/webapp/src/main/elm/Util/Http.elm index f9a030d3..20ebf5cd 100644 --- a/modules/webapp/src/main/elm/Util/Http.elm +++ b/modules/webapp/src/main/elm/Util/Http.elm @@ -164,12 +164,14 @@ errorToString : Http.Error -> String errorToString error = let f sc = - case sc of - 404 -> - "The requested resource doesn't exist." + if sc == 404 then + "The requested resource doesn't exist." - _ -> - "There was an invalid response status: " ++ String.fromInt sc + else if sc >= 400 && sc < 500 then + "Invalid input when processing the request." + + else + "There was an invalid response status: " ++ String.fromInt sc ++ "." in errorToStringStatus error f