From 009bf4c0a3d9a261ea781768c6d5d853c5c7abd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=20B=C3=A4rwinkel?= Date: Sat, 29 Oct 2022 15:06:31 +0200 Subject: [PATCH] Add sendWithCustomExpect function to Api.mustache (#13773) to allow more fine grained error handling. --- .../src/main/resources/elm/Api.mustache | 10 ++++++++-- samples/openapi3/client/elm/src/Api.elm | 10 ++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/elm/Api.mustache b/modules/openapi-generator/src/main/resources/elm/Api.mustache index 2890e9deac9..57b78a2620c 100644 --- a/modules/openapi-generator/src/main/resources/elm/Api.mustache +++ b/modules/openapi-generator/src/main/resources/elm/Api.mustache @@ -3,6 +3,7 @@ module Api exposing , request , send , sendWithCustomError + , sendWithCustomExpect , task , map , withBasePath @@ -55,13 +56,18 @@ send toMsg req = 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 { method = req.method , headers = req.headers , url = Url.Builder.crossOrigin req.basePath req.pathParams req.queryParams , body = req.body - , expect = expectJson mapError toMsg req.decoder + , expect = expect req.decoder , timeout = req.timeout , tracker = req.tracker } diff --git a/samples/openapi3/client/elm/src/Api.elm b/samples/openapi3/client/elm/src/Api.elm index 842a33ca3aa..9d6f5de1e7e 100644 --- a/samples/openapi3/client/elm/src/Api.elm +++ b/samples/openapi3/client/elm/src/Api.elm @@ -3,6 +3,7 @@ module Api exposing , request , send , sendWithCustomError + , sendWithCustomExpect , task , map , withBasePath @@ -55,13 +56,18 @@ send toMsg req = 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 { method = req.method , headers = req.headers , url = Url.Builder.crossOrigin req.basePath req.pathParams req.queryParams , body = req.body - , expect = expectJson mapError toMsg req.decoder + , expect = expect req.decoder , timeout = req.timeout , tracker = req.tracker }