title: Handling Erlang inets http client errors
body: <p>I have an Erlang app which makes a large number of http calls to external sites using inets, using the code below</p>
  
  <pre><code>case http:request(get, {Url, []}, [{autoredirect, false}], []) of
  {ok, {{_, Code, _}, _, Body}}-&gt;
      case Code of
      200 -&gt;
          HandlerFn(Body);
      _ -&gt;
          {error, io:format("~s returned HTTP ~p", [Broker, Code])}
      end;
  Response -&gt; %% block to handle unexpected responses from inets
      {error, io:format("~s returned ~p", [Broker, Response])}
  end.
  </code></pre>
  
  <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>
  
  <p>Thanks.</p>
  
  <p>--</p>
  
  <pre><code>=ERROR REPORT==== 24-Apr-2010::06:49:47 ===
  ** Generic server &lt;0.6618.0&gt; terminating 
  ** Last message in was {connect_and_send,
                             {request,#Ref&lt;0.0.0.139358&gt;,&lt;0.6613.0&gt;,0,http,
                                 {"**********",80},
                                 "*****************************",
                                 [],get,
                                 {http_request_h,undefined,"keep-alive",
                                     undefined,undefined,undefined,undefined,
                                     undefined,undefined,undefined,undefined,
                                     undefined,undefined,undefined,undefined,
                                     undefined,undefined,"news.bbc.co.uk",
                                     undefined,undefined,undefined,undefined,
                                     undefined,undefined,undefined,undefined,
                                     undefined,[],undefined,undefined,undefined,
                                     undefined,"0",undefined,undefined,
                                     undefined,undefined,undefined,undefined,[]},
                                 {[],[]},
                                 {http_options,"HTTP/1.1",infinity,false,[],
                                     undefined,false,infinity},
                                 "************************************",
                                 [],none,[],1272088179114,undefined,undefined}}
  ** When Server state == {state,
                              {request,#Ref&lt;0.0.0.139358&gt;,&lt;0.6613.0&gt;,0,http,
                                  {"******************",80},
                                  "*****************************",
                                  [],get,
                                  {http_request_h,undefined,"keep-alive",
                                      undefined,undefined,undefined,undefined,
                                      undefined,undefined,undefined,undefined,
                                      undefined,undefined,undefined,undefined,
                                      undefined,undefined,"news.bbc.co.uk",
                                      undefined,undefined,undefined,undefined,
                                      undefined,undefined,undefined,undefined,
                                      undefined,[],undefined,undefined,
                                      undefined,undefined,"0",undefined,
                                      undefined,undefined,undefined,undefined,
                                      undefined,[]},
                                  {[],[]},
                                  {http_options,"HTTP/1.1",infinity,false,[],
                                      undefined,false,infinity},
                                  "****************************************",
                                  [],none,[],1272088179114,undefined,undefined},
                              undefined,undefined,undefined,undefined,undefined,
                              {[],[]},
                              {[],[]},
                              undefined,[],nolimit,nolimit,
                              {options,
                                  {undefined,[]},
                                  0,2,5,120000,2,disabled,false,inet,default,
                                  default,[]},
                              {timers,[],undefined},
                              httpc_manager,undefined}
  ** Reason for termination == 
  ** {error,{connect_failed,{#Ref&lt;0.0.0.139358&gt;,{error,nxdomain}}}}
  
  =ERROR REPORT==== 24-Apr-2010::06:49:47 ===
  HTTPC-MANAGER&lt;httpc_manager&gt; handler (&lt;0.6618.0&gt;, started) failed to connect and/or send request #Ref&lt;0.0.0.139358&gt;
     Result: {error,{connect_failed,{#Ref&lt;0.0.0.139358&gt;,{error,nxdomain}}}}
  </code></pre>