-
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8b9fc53
Add `Req.TransportError`, support returning exceptions in `put_plug`
wojtekmach ce3f4fd
up
wojtekmach e7dd7eb
Update lib/req/transport_error.ex
wojtekmach 5e498df
Add Req.Test.transport_error/2
wojtekmach 44412f5
update docs
wojtekmach File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
defmodule Req.TransportError do | ||
@moduledoc """ | ||
Represents an error with the transport used by an HTTP connection. | ||
|
||
This is a standardised exception that all Req adapters should use for transport layer related | ||
wojtekmach marked this conversation as resolved.
Show resolved
Hide resolved
|
||
errors. | ||
|
||
This exception is based on `Mint.TransportError`. | ||
""" | ||
|
||
defexception [:reason] | ||
|
||
@impl true | ||
def message(%__MODULE__{reason: reason}) do | ||
Mint.TransportError.message(%Mint.TransportError{reason: reason}) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
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 forMint.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 toReq.Test
.reason
would be an atom, so thatessentially stores
conn.private.req_transport_error = %Req.TransportError{reason: :timeout}
, which then you can use to return the error. Thoughts?