nitins818@gmail.com has asked for the wisdom of the Perl Monks concerning the following question:

Error handling on_fault

I made a service using soap::lite, If my service crashes
my $soap = SOAP::Lite
->service("$wsdl")
->proxy($proxy, timeout => 5 )
-> on_fault( sub {

## I am here after there is any fault in service
i want to return some error_result to the caller file.

like : return (0, 'Some error occurred');
};

Can anyone help me How to return params to the caller .

login.mp -> adapter.pm ( here soap::lite calls service nad return response to login.mp )
  • Comment on Error handling on_fault and return params to the caller file (abc.mp)

Replies are listed 'Best First'.
Re: Error handling on_fault and return params to the caller file (abc.mp)
by mr.nick (Chaplain) on Jun 28, 2012 at 13:44 UTC
    Since SOAP::Lite natively throws exceptions via die() when an error occurs (I think?), you should do the same in your on_fault routine.

    Here's what I do:

    $soap->on_fault( sub { my ( $soap, $res ) = @_; if ($res) { if ( ref $res ) { die join( '; ', $res->faultcode, $res->faultstring +, $res->faultdetail ) . "\n"; } else { die $res; } } else { die "Soap Fault: " . $soap->transport->status . "\n"; } } );

    Then later in the client...

    eval { $soap->Method("arguments"); }; if ($@) { // provide some user feedback about the error in $@ }

    mr.nick ...

      SOAP::LITE is single threaded ???
      If it is true then how to change it to multiple?

      It can help me to save my client if my service server dies ...

      Please Help ...
        create a new soap lite object in each subthread
Re: Error handling on_fault and return params to the caller file (abc.mp)
by locked_user sundialsvc4 (Abbot) on Jun 28, 2012 at 15:50 UTC

    The RPC::Any package-family has an interesting approach to a similar problem.   The outer-level server framework wraps the handler-routines in an exception-handling block, and it also defines a set of structured error classes.   If any handler encounters either an impossible situation or a bug, it throws an exception.   The exception is caught and an error-response is returned.   Because of the fact that you can throw objects, not just strings, the response can be quite customized because the “catcher” has more than just a string to work with.   You might want to take a look at what they did as a source of good ideas.   Also Exception::Class.   It worked really well for me ... came out very clean and straightforward.