Handling Erlang inets http client errors
Posted
by Justin
on Stack Overflow
See other posts from Stack Overflow
or by Justin
Published on 2010-04-24T06:28:45Z
Indexed on
2010/04/24
6:33 UTC
Read the original article
Hit count: 450
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}}->
case Code of
200 ->
HandlerFn(Body);
_ ->
{error, io:format("~s returned HTTP ~p", [Broker, Code])}
end;
Response -> %% block to handle unexpected responses from inets
{error, io:format("~s returned ~p", [Broker, Response])}
end.
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 ?
Thanks.
--
=ERROR REPORT==== 24-Apr-2010::06:49:47 === ** Generic server <0.6618.0> terminating ** Last message in was {connect_and_send, {request,#Ref<0.0.0.139358>,<0.6613.0>,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<0.0.0.139358>,<0.6613.0>,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<0.0.0.139358>,{error,nxdomain}}}}
=ERROR REPORT==== 24-Apr-2010::06:49:47 === HTTPC-MANAGER handler (<0.6618.0>, started) failed to connect and/or send request #Ref<0.0.0.139358> Result: {error,{connect_failed,{#Ref<0.0.0.139358>,{error,nxdomain}}}}
© Stack Overflow or respective owner