Skip to content

Instantly share code, notes, and snippets.

@chrisbuttery
Forked from jasondew/alternative.elm
Created March 17, 2016 02:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisbuttery/26642ac5f9a32d51f92c to your computer and use it in GitHub Desktop.
Save chrisbuttery/26642ac5f9a32d51f92c to your computer and use it in GitHub Desktop.
type Action
= Updated Response
| APIError Error
update : Action -> Model -> ( Model, Effects Action )
update action model =
case action of
Updated response -> -- do things
APIError error ->
let
_ =
case error of
Http.Timeout ->
Debug.log "API timeout" error
Http.NetworkError ->
Debug.log "Network error contacting API" error
Http.UnexpectedPayload payload ->
Debug.log ("Unexpected payload from API: " ++ payload) error
Http.BadResponse status payload ->
Debug.log ("Unexpected status/payload from API: " ++ (toString status) ++ "/" ++ payload) error
in
( model, Effects.none )
requestUpdate : Effects Action
requestUpdate =
Http.get decoder url
|> Task.map Updated
|> (flip Task.onError) (Task.succeed << APIError)
|> Effects.task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment