edgurgel / httpoison

Yet Another HTTP client for Elixir powered by hackney
https://hex.pm/packages/httpoison
MIT License
2.23k stars 339 forks source link

(HTTPoison.Error) :closed needs a proper message that its from hackney #432

Closed dkuku closed 3 years ago

dkuku commented 3 years ago

I have an error with "https://www.sejm.gov.pl/", (HTTPoison.Error) :closed I can get to google with HTTPPoison (iex(3)) and this url: https://www.sejm.gov.pl/ with curl works just fine iex(2) Steps to reproduce:


iex(1)> HTTPoison.start                                                                                                
{:ok, []} 

iex(2)> response = HTTPoison.get! "https://www.sejm.gov.pl/Sejm9.nsf/poslowie.xsp?type=A"                              
** (HTTPoison.Error) :closed (httpoison 1.8.0) lib/httpoison.ex:156: HTTPoison.request!/5

iex(2)> System.cmd("curl", ["https://www.sejm.gov.pl/Sejm9.nsf/poslowie.xsp?type=A"])    
% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current   Dload  Upload   Total   Spent    Left  Speed
      100       172k        100         172k                0             0        523k      0      --:--:--  --:--:--   --:--:--  523k
{"<!DOCTYPE html>\n<html lang=\"pl\">\n<head>\n<script type=\"text/javascript">if(!navigator.cookieEnabled)window.location.href=\"https://www.sejm.gov.pl/Sejm9.nsf/poslowie.xsp?type=A\\u0026SessionID=36746C5A545C5C7741821F66E90B55DD0CA7419E\";</script>\n<title>Aktualni pos&#322;owie</title>\n<link rel=\"SHORTCUT ICON\" href=\"https://www.sejm.gov.pl/favicon.ico\">\n<meta name=\"charset\" content=\"utf-8\">pocz&#261;tek sw&oacute;j bierze\n      z woli\n      narodu\"</span><h2 class=\"wcag-hide\">Menu ...,

iex(3)> response = HTTPoison.get! "https://google.com"                                    
%HTTPoison.Response{
  body: "<HTML><HEAD><meta http-equiv=\"content-type\" content=\"text/html;charset=utf-8\">\n<TITLE>301 Moved</TITLE></HEAD><BODY>\n<H1>301 Moved</H1>\nThe document has moved\n<A HREF=\"https://www.google.com/\">here</A>.\r\n</BODY></HTML>

I saw an old post from 2018 that it may be a hackney issue - and the solution was to upgrade hackney. https://github.com/edgurgel/httpoison/issues/326 So even if it is hackney - we should probably handle it and show some kind of message to the user

edgurgel commented 3 years ago

Hi @dkuku ,

What do you mean by handle it? If you use .get instead of .get! you should get a proper HTTPoison.Error. Is that what you mean?

dkuku commented 3 years ago

I scrolled the wrong command in iex - I was using get before when I pasted the initial title

I was thinking more of pointing the user that the error comes from hackney - I only found it out only because I saw that its using hackney and I checked if it works in hackney, The original atom is converted to string anyway so it would be good to add something that points to hackney instead just wrapping it in a struct because its a bit confusing. maybe hackney returned: and the reason

edgurgel commented 3 years ago

The README.md very clearly states that we use hackney under the hood. I don't see us changing the return of a function so that people are aware of which libs are used. I think it's part of the research that people should do around using open source libraries. Thanks for opening the issue