Reputation:
I have written a perl script that connects using Soap::Lite
and collect data from a web-service and update a database. This works well, until the password gets locked out and I get a server 500 error
which is where my question comes in. How do I let the Soap::Lite
query die
when it does not make a successful connection, so it does not continue with the rest of the script?
.....
my $host = "hostname";
my $user = "user";
my $pass = "pass";
$soap_proxy = "https://" . $user . ":" . $pass . "@" . $host . ":8090/services/ApiService";
$uri = "http://api.config.common.com";
$client = new SOAP::Lite
uri => $uri,
proxy => $soap_proxy,
autotype => 0;
my $soap_respons = $client->getSomething();
....
I have tried the usual or die $!
but that does not die
like other queries do and still continues with the remaining script.
according to the SOAP::Lite
examples on CPAN, you could use:
if ($@) {
die $@;
}
But I do not know where to put this. I tried directly under my $soap_respons
but still it does not die.
Upvotes: 0
Views: 151
Reputation: 1473
You could set the on_fault
callback. This way you wouldn't have to check every response.
$client->on_fault(sub { die($_[1]) });
Upvotes: 1
Reputation:
SOAP::Lite
queries will give a fault
with a faultstring
result if errors occur, something like this should work.
die $soap_respons->faultstring if ($soap_respons->fault);
print $soap_respons->result, "\n";
Upvotes: 1