aboutsummaryrefslogtreecommitdiff
path: root/src/client/ServerCommunication.elm
diff options
context:
space:
mode:
authorJoris Guyonvarch2015-07-19 17:28:19 +0200
committerJoris Guyonvarch2015-07-19 17:28:19 +0200
commit331d506281760ac62e8f1715ef729e1b2a91e280 (patch)
treea26e49d9a41de26fbb5602b293f44c5f7f592efc /src/client/ServerCommunication.elm
parent0d589e12a0c32936303de46b1e462dd19648170d (diff)
downloadbudget-331d506281760ac62e8f1715ef729e1b2a91e280.tar.gz
budget-331d506281760ac62e8f1715ef729e1b2a91e280.tar.bz2
budget-331d506281760ac62e8f1715ef729e1b2a91e280.zip
Showing either error or success message at sign in page
Diffstat (limited to 'src/client/ServerCommunication.elm')
-rw-r--r--src/client/ServerCommunication.elm26
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