Skip to content

Commit 009bf4c

Browse files
authored
Add sendWithCustomExpect function to Api.mustache (#13773)
to allow more fine grained error handling.
1 parent 458ea56 commit 009bf4c

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

  • modules/openapi-generator/src/main/resources/elm
  • samples/openapi3/client/elm/src

modules/openapi-generator/src/main/resources/elm/Api.mustache

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module Api exposing
33
, request
44
, send
55
, sendWithCustomError
6+
, sendWithCustomExpect
67
, task
78
, map
89
, withBasePath
@@ -55,13 +56,18 @@ send toMsg req =
5556

5657

5758
sendWithCustomError : (Http.Error -> e) -> (Result e a -> msg) -> Request a -> Cmd msg
58-
sendWithCustomError mapError toMsg (Request req) =
59+
sendWithCustomError mapError toMsg req =
60+
sendWithCustomExpect (expectJson mapError toMsg) req
61+
62+
63+
sendWithCustomExpect : (Json.Decode.Decoder a -> Http.Expect msg) -> Request a -> Cmd msg
64+
sendWithCustomExpect expect (Request req) =
5965
Http.request
6066
{ method = req.method
6167
, headers = req.headers
6268
, url = Url.Builder.crossOrigin req.basePath req.pathParams req.queryParams
6369
, body = req.body
64-
, expect = expectJson mapError toMsg req.decoder
70+
, expect = expect req.decoder
6571
, timeout = req.timeout
6672
, tracker = req.tracker
6773
}

samples/openapi3/client/elm/src/Api.elm

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module Api exposing
33
, request
44
, send
55
, sendWithCustomError
6+
, sendWithCustomExpect
67
, task
78
, map
89
, withBasePath
@@ -55,13 +56,18 @@ send toMsg req =
5556

5657

5758
sendWithCustomError : (Http.Error -> e) -> (Result e a -> msg) -> Request a -> Cmd msg
58-
sendWithCustomError mapError toMsg (Request req) =
59+
sendWithCustomError mapError toMsg req =
60+
sendWithCustomExpect (expectJson mapError toMsg) req
61+
62+
63+
sendWithCustomExpect : (Json.Decode.Decoder a -> Http.Expect msg) -> Request a -> Cmd msg
64+
sendWithCustomExpect expect (Request req) =
5965
Http.request
6066
{ method = req.method
6167
, headers = req.headers
6268
, url = Url.Builder.crossOrigin req.basePath req.pathParams req.queryParams
6369
, body = req.body
64-
, expect = expectJson mapError toMsg req.decoder
70+
, expect = expect req.decoder
6571
, timeout = req.timeout
6672
, tracker = req.tracker
6773
}

0 commit comments

Comments
 (0)