Add sendWithCustomExpect function to Api.mustache (#13773)

to allow more fine grained error handling.
This commit is contained in:
Tom Bärwinkel 2022-10-29 15:06:31 +02:00 committed by GitHub
parent 458ea56896
commit 009bf4c0a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 4 deletions

View File

@ -3,6 +3,7 @@ module Api exposing
, request , request
, send , send
, sendWithCustomError , sendWithCustomError
, sendWithCustomExpect
, task , task
, map , map
, withBasePath , withBasePath
@ -55,13 +56,18 @@ send toMsg req =
sendWithCustomError : (Http.Error -> e) -> (Result e a -> msg) -> Request a -> Cmd msg sendWithCustomError : (Http.Error -> e) -> (Result e a -> msg) -> Request a -> Cmd msg
sendWithCustomError mapError toMsg (Request req) = sendWithCustomError mapError toMsg req =
sendWithCustomExpect (expectJson mapError toMsg) req
sendWithCustomExpect : (Json.Decode.Decoder a -> Http.Expect msg) -> Request a -> Cmd msg
sendWithCustomExpect expect (Request req) =
Http.request Http.request
{ method = req.method { method = req.method
, headers = req.headers , headers = req.headers
, url = Url.Builder.crossOrigin req.basePath req.pathParams req.queryParams , url = Url.Builder.crossOrigin req.basePath req.pathParams req.queryParams
, body = req.body , body = req.body
, expect = expectJson mapError toMsg req.decoder , expect = expect req.decoder
, timeout = req.timeout , timeout = req.timeout
, tracker = req.tracker , tracker = req.tracker
} }

View File

@ -3,6 +3,7 @@ module Api exposing
, request , request
, send , send
, sendWithCustomError , sendWithCustomError
, sendWithCustomExpect
, task , task
, map , map
, withBasePath , withBasePath
@ -55,13 +56,18 @@ send toMsg req =
sendWithCustomError : (Http.Error -> e) -> (Result e a -> msg) -> Request a -> Cmd msg sendWithCustomError : (Http.Error -> e) -> (Result e a -> msg) -> Request a -> Cmd msg
sendWithCustomError mapError toMsg (Request req) = sendWithCustomError mapError toMsg req =
sendWithCustomExpect (expectJson mapError toMsg) req
sendWithCustomExpect : (Json.Decode.Decoder a -> Http.Expect msg) -> Request a -> Cmd msg
sendWithCustomExpect expect (Request req) =
Http.request Http.request
{ method = req.method { method = req.method
, headers = req.headers , headers = req.headers
, url = Url.Builder.crossOrigin req.basePath req.pathParams req.queryParams , url = Url.Builder.crossOrigin req.basePath req.pathParams req.queryParams
, body = req.body , body = req.body
, expect = expectJson mapError toMsg req.decoder , expect = expect req.decoder
, timeout = req.timeout , timeout = req.timeout
, tracker = req.tracker , tracker = req.tracker
} }