-
Notifications
You must be signed in to change notification settings - Fork 152
New step: expect
#493
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
base: main
Are you sure you want to change the base?
New step: expect
#493
Conversation
lib/req/unexpected_response_error.ex
Outdated
@@ -0,0 +1,16 @@ | |||
defmodule Req.UnexpectedResponseError do | |||
defexception [:expected, :response] |
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.
maybe instead of storing the full response we keep just:
defexception [:expected, :response] | |
defexception [:expected_status, :status, :headers, :body] |
i.e. no resp.private
(nor resp.assigns
, #492)
@@ -0,0 +1,16 @@ | |||
defmodule Req.UnexpectedResponseError do |
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.
another idea for calling this:
defmodule Req.UnexpectedResponseError do | |
defmodule Req.UnexpectedResponseStatusError do |
Maybe we put it after decompress but before decode so the exception message just prints the string |
I still feel
At least for most OpenAPI, non-redirecting APIs; which are the most commons anyway. I think it is worth it to keep it around, and trivial enough where it doesn't add much complexity, if any. |
Thanks for the feedback about expect. I concede response.ok is ubiquitous due to being part of the Web platform. I think in pattern matches, by the way of falling into another code branch that is for transport errors, expect "wins": case resp do
- {:ok, %{ok?: true} = resp -> ...
- {:ok, resp} -> ...
- {:error, e} -> ...
+ {:ok, resp} ->
+ {:error, e} -> ...
end In other cases - if resp.status in 200..299 do
+ if resp.ok? do yeah, that looks really clean. My personal opinion though is it doesn't justify adding a new field to the struct even if that's some false scarcity argument. |
Most likely useful for default steps behaviour and things like that, purely a semantic meaning that sometimes it is useful. I have come across that |
This is a replacement for https://hexdocs.pm/req/Req.Steps.html#handle_http_errors/1 which will be deprecated and removed in Req 1.0.
Some more context here:
handle_http_errors
: Support:response
and:exception
#193In a nutshell: