-
Notifications
You must be signed in to change notification settings - Fork 120
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
Add Req.TransportError
and Req.Test.transport_error/2
#323
Conversation
lib/req/steps.ex
Outdated
plug = fn _conn -> | ||
%Req.TransportError{reason: :econnrefused} | ||
end |
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.
hey @whatyouhide @josevalim I have a favour ask, what do you think about this API?
I initially thought about returning just an atom:
plug = fn _conn ->
:econnrefused
end
or to stand out even more from the Plug contract (which obviously does not supports it) maybe throw(:econnrefused)
but figured exception is extensible. I hope not but maybe people want to check for Mint.HTTPError
, Finch.HTTPError
, etc. Which I'm not standardising on btw, meaning, Finch adapter turns Mint.TransportError to Req.TransportError but other ones it might return are returned as is.
Any feedback appreciated!
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.
I like this more than the atom.
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.
I think this is better than the atom indeed. You could also have some sort of Req.Plug.halt(conn, reason)
, if you want to keep the Plug contract, and then you store the reason somewhere in the connection.
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.
Oh that's a very good idea, because it allows you to keep the public API flexible!
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.
reason being exception struct or atom and friends?
maybe Req.Test.transport_error(conn, reason)?
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.
Yeah I think Req.Test.transport_error(conn, reason)
is the same idea, but it reads better. I also like that it keeps it scoped to Req.Test
. reason
would be an atom, so that
Req.Test.transport_error(conn, :timeout)
essentially stores conn.private.req_transport_error = %Req.TransportError{reason: :timeout}
, which then you can use to return the error. Thoughts?
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.
Beautiful
Co-authored-by: Andrea Leopardi <[email protected]>
Req.TransportError
, support returning exceptions in put_plug
Req.TransportError
and Req.Test.transport_error/2
usable in put_plug
Req.TransportError
and Req.Test.transport_error/2
usable in put_plug
Req.TransportError
and Req.Test.transport_error/2
@whatyouhide @josevalim Thank you! |
No description provided.