Forum Discussion

Joe_Pruitt's avatar
Jul 19, 2004

Tip: How to check for HTTP errors with SOAP::Lite

A question was posed to me as to how one would check for HTTP errors (500: Can't Connect; 401: Authentication Required; etc). If you make a call with the SOAP::Lite package a HTTP level error will cause the script to die.

 

 

What you need to do is use an eval block around your method calls. Here is a script of code illustrating one solution:

 

 

 
 eval { 
     $soap_response = $soap->get_list(); 
 }; 
   
  If at this point $@ is not NULL, then the eval failed from an HTTP connection error. 
  Otherwise, when it's not null everything is OK. 
  
 if ( $@ ) 
 { 
     @tokens = split /\s+/, $@; 
     if ( "401" eq $tokens[0] ) 
     { 
         print "AUTH ERROR ($tokens[0]): '$@'\n"; 
     } 
     else 
     { 
         print "OTHER HTTP ERROR ($tokens[0]): '$@'\n"; 
     } 
 } 
 else 
 { 
     print "Connection OK, proceeding...\n"; 
 &125

 

-Joe
No RepliesBe the first to reply