diff options
author | Joris Guyonvarch | 2015-07-19 17:28:19 +0200 |
---|---|---|
committer | Joris Guyonvarch | 2015-07-19 17:28:19 +0200 |
commit | 331d506281760ac62e8f1715ef729e1b2a91e280 (patch) | |
tree | a26e49d9a41de26fbb5602b293f44c5f7f592efc /src/client/ServerCommunication.elm | |
parent | 0d589e12a0c32936303de46b1e462dd19648170d (diff) |
Showing either error or success message at sign in page
Diffstat (limited to 'src/client/ServerCommunication.elm')
-rw-r--r-- | src/client/ServerCommunication.elm | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/src/client/ServerCommunication.elm b/src/client/ServerCommunication.elm index e29b084..d581f82 100644 --- a/src/client/ServerCommunication.elm +++ b/src/client/ServerCommunication.elm @@ -8,8 +8,10 @@ import Signal import Task import Task exposing (Task) import Http +import Json.Decode exposing (..) import Update as U +import Update.SignIn exposing (..) type Communication = NoCommunication @@ -55,9 +57,29 @@ communicationToAction communication response = case communication of NoCommunication -> U.NoOp - SignIn _ -> - U.NoOp + SignIn login -> + U.UpdateSignIn (ValidLogin login) SignOut -> U.SignIn else + decodeResponse + response + (\error -> + case communication of + SignIn _ -> + U.UpdateSignIn (ErrorLogin error) + _ -> + U.NoOp + ) + +decodeResponse : Http.Response -> (String -> U.Action) -> U.Action +decodeResponse response responseToAction = + case response.value of + Http.Text text -> + case decodeString ("message" := string) text of + Ok x -> + responseToAction x + Err _ -> + U.NoOp + Http.Blob _ -> U.NoOp |