Hello all,
I am using post method to register a new user to the server and my command look like this
createPostCommand : User -> Cmd Msg
createPostCommand user =
Http.post
{ url = "http://localhost:4000/users"
, body = Http.jsonBody (userEncoder user)
, expect = Http.expectJson GotResult userDecoder
}
Me message type for the response is defined like
GotResult (Result Http.Error String)
But my server upon HTTP 400 returns a list with all the validation errors like
[ “user_name” : “can’t be blank”]
How can I set to the post method that upon 201 response I want it to use userDecoder
and decode the User Returned but when 400 comes buck to use some userErrorDecoder
and give me back the validation errors the server responded with ?
and consequently in my update method receive the appropriate response record ?
any help or direction towards an online resource, tutorial or even book would be appreciated.
Cheers