-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[elm] add function to allow more fine grained error handling #13773
[elm] add function to allow more fine grained error handling #13773
Conversation
to allow more fine grained error handling.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your PR @7omb. Please see the note.
|
||
|
||
sendWithCustomExpect : (Json.Decode.Decoder a -> Http.Expect msg) -> Request a -> Cmd msg | ||
sendWithCustomExpect expect (Request req) = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure I'm following why this takes a decoder to message function. Can you give me a basic example of what you would to with it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The decoders in the signature are the ones provided by the Request
s from Api/Request/Default.elm
. To use sendWithCustomExpect
one has to provide the logic to interpret the response body given the decoders.
My goal was make it possible to use a custom error type (the current send
and sendWithCustomError
both expect a Http.Error
). A shortened example for String
that e.g. accesses the body of a Http.BadStatus_
could e.g. look like this:
customSend : (Result String a -> msg) -> Api.Request a -> Cmd msg
customSend toMsg req =
Api.sendWithCustomExpect (Http.expectStringResponse toMsg << decodeResponse) req
decodeResponse : Json.Decode.Decoder a -> Http.Response String -> Result String a
decodeResponse decoder response =
case response of
...
Http.BadStatus_ _ body ->
Err body
...
Where decodeResponse
goes from:
Json.Decode.Decoder a -> (Http.Response String -> Result String a)
and expectStringResponse toMsg
from:
(Response String -> Result String a) -> Expect msg
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes, that makes sense to support. Thanks for clarifying!
@wing328 is the failed build to be expected? |
@eriktim thanks for reviewing the change. The circleci build failure can be ignore. when you've time, can you please PM me via Slack? thanks https://join.slack.com/t/openapi-generator/shared_invite/zt-12jxxd7p2-XUeQM~4pzsU9x~eGLQqX2g |
Thanks, @7omb! |
Thank you for talking the time to review the PR @eriktim |
This is a backwards compatible change. It adds the additional function
sendWithCustomExpect
to the provided helper functions inApi.elm
to make requests.It can be used to implement a more fine grained error handling as described here. Before it was e.g. not possible to access the response body if the server responded with an error like 404.
@eriktim
PR checklist
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*
.For Windows users, please run the script in Git BASH.
master
(6.1.0) (minor release - breaking changes with fallbacks),7.0.x
(breaking changes without fallbacks)