Elm: Chain Http.send and Http.get -
i'm (a beginner) having type issue trying chain http calls in elm application:
http.send ... `task.andthen` (\_ -> http.get ...)
this because http.send
return type task rawerror response
, , http.get
return type task error value
.
any suggestion on how make them work together?
edit1:
maybe maperror
solution?
edit2:
i'm not saying first call failed, i'm sure works. compiler doesn't validate code:
the right argument of `andthen` causing type mismatch. 135│ http.send http.defaultsettings config 136│> `task.andthen` (\_ -> http.get (json.decode.list userjsondecoder) "http://localhost:3000/") `andthen` expecting right argument a: http.response -> task http.rawerror right argument is: http.response -> task http.error (list user)
you need way map rawerror
error
, can use task.maperror
suggested in first edit. 1 possibility be:
rawerrortoerror : http.rawerror -> http.error rawerrortoerror rawerror = case rawerror of http.rawtimeout -> http.timeout http.rawnetworkerror -> http.networkerror http.send http.defaultsettings config |> task.maperror rawerrortoerror `task.andthen` ...
Comments
Post a Comment