DreamT has asked for the wisdom of the Perl Monks concerning the following question:

Hi! I'm using Frontier::Client to connect to an XML RPC-server.

my ($anrop, @argument) = @_; $server_url = 'http://url'; $server = Frontier::Client->new('url' => $server_url, 'encoding' => 'ISO-8859-1'); $result = $server->call($anrop, @argument); print "Completed!"; # Result handling.

It works, but the script dies if the XML RPC Throws a fault code that normally should be handled (i.e. "Completed!" never gets printed). Why?

Replies are listed 'Best First'.
Re: Frontier::Client - script quits on error respons
by Eliya (Vicar) on Feb 18, 2011 at 14:48 UTC

    Have you tried wrapping the call in eval {}?  As I read the docs, the method ->call() is expected to raise an exception (i.e. die) on error.

      I haven't tried that, since I didn't see how I can capture the returned error code. But maybe that is stored in $@ ?

        The call() method ends like this:

        sub call { ... if ($result->{'type'} eq 'fault') { die "Fault returned from XML RPC Server, fault code " . $resul +t->{'value'}[0]{'faultCode'} . ": " . $result->{'value'}[0]{'faultString'} . "\n"; } return $result->{'value'}[0]; }

        so, when it dies (raises an exception), you'll get the message "Fault returned from XML RPC Server, fault code ...: ..." in $@.

        As you can see, the message includes the faultCode and faultString, so you'd have to extract it from there.

        In case there is no fault, it returns whatever is in $result->{'value'}[0].