{"id":510,"date":"2022-08-30T15:02:33","date_gmt":"2022-08-30T15:02:33","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/09\/handling-erlang-inets-http-client-errors-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:02:33","modified_gmt":"2022-08-30T15:02:33","slug":"handling-erlang-inets-http-client-errors-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/handling-erlang-inets-http-client-errors-collection-of-common-programming-errors\/","title":{"rendered":"Handling Erlang inets http client errors-Collection of common programming errors"},"content":{"rendered":"<p>I have an Erlang app which makes a large number of http calls to external sites using inets, using the code below<\/p>\n<pre><code>case http:request(get, {Url, []}, [{autoredirect, false}], []) of\n{ok, {{_, Code, _}, _, Body}}-&gt;\n    case Code of\n    200 -&gt;\n        HandlerFn(Body);\n    _ -&gt;\n        {error, io:format(\"~s returned HTTP ~p\", [Broker, Code])}\n    end;\nResponse -&gt; %% block to handle unexpected responses from inets\n    {error, io:format(\"~s returned ~p\", [Broker, Response])}\nend.\n<\/code><\/pre>\n<p>There is an explicit block to handle anything strange inets might return [Response]. Despite this, I still get what look like inets error reports dumped to the console [sample below]. What am I doing wrong here ? Do I need to configure some kind of inets error handler elsewhere ?<\/p>\n<p>Thanks.<\/p>\n<p>&#8212;<\/p>\n<pre><code>=ERROR REPORT==== 24-Apr-2010::06:49:47 ===\n** Generic server  terminating \n** Last message in was {connect_and_send,\n                           {request,#Ref,,0,http,\n                               {\"**********\",80},\n                               \"*****************************\",\n                               [],get,\n                               {http_request_h,undefined,\"keep-alive\",\n                                   undefined,undefined,undefined,undefined,\n                                   undefined,undefined,undefined,undefined,\n                                   undefined,undefined,undefined,undefined,\n                                   undefined,undefined,\"news.bbc.co.uk\",\n                                   undefined,undefined,undefined,undefined,\n                                   undefined,undefined,undefined,undefined,\n                                   undefined,[],undefined,undefined,undefined,\n                                   undefined,\"0\",undefined,undefined,\n                                   undefined,undefined,undefined,undefined,[]},\n                               {[],[]},\n                               {http_options,\"HTTP\/1.1\",infinity,false,[],\n                                   undefined,false,infinity},\n                               \"************************************\",\n                               [],none,[],1272088179114,undefined,undefined}}\n** When Server state == {state,\n                            {request,#Ref,,0,http,\n                                {\"******************\",80},\n                                \"*****************************\",\n                                [],get,\n                                {http_request_h,undefined,\"keep-alive\",\n                                    undefined,undefined,undefined,undefined,\n                                    undefined,undefined,undefined,undefined,\n                                    undefined,undefined,undefined,undefined,\n                                    undefined,undefined,\"news.bbc.co.uk\",\n                                    undefined,undefined,undefined,undefined,\n                                    undefined,undefined,undefined,undefined,\n                                    undefined,[],undefined,undefined,\n                                    undefined,undefined,\"0\",undefined,\n                                    undefined,undefined,undefined,undefined,\n                                    undefined,[]},\n                                {[],[]},\n                                {http_options,\"HTTP\/1.1\",infinity,false,[],\n                                    undefined,false,infinity},\n                                \"****************************************\",\n                                [],none,[],1272088179114,undefined,undefined},\n                            undefined,undefined,undefined,undefined,undefined,\n                            {[],[]},\n                            {[],[]},\n                            undefined,[],nolimit,nolimit,\n                            {options,\n                                {undefined,[]},\n                                0,2,5,120000,2,disabled,false,inet,default,\n                                default,[]},\n                            {timers,[],undefined},\n                            httpc_manager,undefined}\n** Reason for termination == \n** {error,{connect_failed,{#Ref,{error,nxdomain}}}}\n\n=ERROR REPORT==== 24-Apr-2010::06:49:47 ===\nHTTPC-MANAGER handler (, started) failed to connect and\/or send request #Ref\n   Result: {error,{connect_failed,{#Ref,{error,nxdomain}}}}\n<\/code><\/pre>\n<p id=\"rop\"><small>Originally posted 2013-11-09 20:02:27. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I have an Erlang app which makes a large number of http calls to external sites using inets, using the code below case http:request(get, {Url, []}, [{autoredirect, false}], []) of {ok, {{_, Code, _}, _, Body}}-&gt; case Code of 200 -&gt; HandlerFn(Body); _ -&gt; {error, io:format(&#8220;~s returned HTTP ~p&#8221;, [Broker, Code])} end; Response -&gt; %% [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-510","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/510","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=510"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/510\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=510"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=510"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=510"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}