Description
The documentation says that:
The options keyword can also take special entry for headers and options, which are passed to the underlying Request. See the documentation of HTTPoison for details.
This is misleading because it does not appear to support all available HTTPoison options. Specifically, when trying to conduct a GoogleRoads.snap_to_roads\3
request asynchronously using the stream_to
option provided by HTTPoison, an exception occurs.
Steps To Reproduce
- Run the following command from the iex console.
GoogleRoads.snap_to_roads("-37.78926|145.29083,-37.78939|145.29189,-37.78914|145.29193,-37.78865|145.29203,-37.78786|145.29219,-37.78787|145.29246,-37.78784|145.2927", true, options: [stream_to: self()])
Expected Outcome
It returns a map containing the reference to the process id where the async response of the request will be streamed.
Actual Outcome
It returns a FunctionClauseError
Reason
This occurs because the underlying HTTPoison response returned when the stream_to
option is passed is not a normal %HTTPoison.Response{}
but a %HTTPoison.AsyncResponse{}
. In the GoogleRoads wrapper this kind of response hasn't been pattern matched, leading to an exception where none of the available clauses match. More specifically, the async response does not contain a body
field like the one found in a normal response, but instead contains an id
field referencing the process id it is streaming to.
Recommendations
This type of response should be pattern matched providing the ability to return a response containing the process id rather than a body. I am happy to write this and submit a pull request for this.
I envisage the code to be as simple as def wrap({:ok, %{id: id}}), do: {:ok, %{id: id}}
plus associated unit tests if there is any. I have tested this change locally and it appears to behave correctly.
Thanks,
Robospecta