What error are you getting? It looks like you're asking Elm to decode a player 
when you know you're not going to be getting one.

> On Mar 6, 2017, at 12:19 AM, Long Nguyen <lnguye...@gmail.com> wrote:
> 
> Hello,
> 
> I have the following helper functions to trigger the DELETE request of a 
> resource.
> 
> deletePlayer : Player -> Cmd Msg
> deletePlayer player =
>     restRequest (hostUrl ++ "/players/" ++ (toString player.id))
>         (playerEncode player)
>         playerDecoder
>         DELETE
>         |> Http.send (PlayerMsg_ << OnDeletePlayer)
> 
> restRequest : String -> JE.Value -> JD.Decoder a -> HTTPMethod -> 
> Http.Request a
> restRequest url encode decoder method =
>     Http.request
>         { body = encode |> Http.jsonBody
>         , expect = Http.expectJson decoder
>         , headers = []
>         , method = toString method
>         , timeout = Nothing
>         , url = url
>         , withCredentials = False
>         }
> 
> And in my Update method I have the following code.
> 
> case msg of
>         ....
>         DeletePlayer id ->
>             let
>                 maybePlayer =
>                     playersModel.players
>                         |> List.filter (\player -> player.id == id)
>                         |> List.head
>             in
>                 case maybePlayer of
>                     Just player ->
>                             ( { playersModel | idToDelete = player.id }
>                             , API.deletePlayer player )
> 
>                     Nothing ->
>                         ( playersModel, Cmd.none )
> 
>         OnDeletePlayer (Ok deletedPlayer) ->
>             Debug.log ("Ok")
>                 ( playersModel, Cmd.none)
> 
>         OnDeletePlayer (Err error) ->
>             Debug.log ("Error")
>                 ( playersModel, Cmd.none )
>     
> 
> The HTTP request got executed, and the resource gets deleted; however, the 
> problem is that Elm always trigger the "OnDeletePlayer (Err error)" branch of 
> the Update function. I'm using JSON Server, and after the request is 
> executed, the response body is "{}" with 200 as Status Code.
> 
> Please help me in structuring my Http.request so that the "OnDeletePlayer (Ok 
> deletedPlayer)" branch gets executed upon success.
> 
> Much appreciated!
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Elm Discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to elm-discuss+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to