Loading ...
Sorry, an error occurred while loading the content.

279RE: SOAP: Fault handling

Expand Messages
  • Paul Kulchenko
    May 2, 2001
      Hi, Garrett!

      First of all, I updated guide with new examples, that fix couple of
      typos there ($! instead of $@ and faultdetail instead of
      faultstring). I also updated .zip and .tar.gz archives. Correct
      example on client side looks like:

      #!perl -w
      use SOAP::Lite
      on_fault => sub { my($soap, $res) = @_;
      eval { die ref $res ? $res->faultstring :
      $soap->transport->status };
      return ref $res ? $res : new SOAP::SOM;
      };

      my $soap = SOAP::Lite
      -> uri('http://www.soaplite.com/Temperatures')
      -> proxy('http://services.soaplite.com/temper.cgi');

      defined (my $temp = $soap->c2f(37.5)->result) or die;
      print $temp;

      On server side there is nothing special. If you want to return fault
      on client side you may simply die with message:

      die "Oops, this operation is not allowed\n";

      or use SOAP::Fault if you need more control over fault information:

      die SOAP::Fault->faulcode('Server.Authentication')
      ->faultstring('Wrong password');

      Take a look into examples/My/Parameters.pm for more information on
      die calls.

      Let me know if it doesn't help or you need more complex examples.

      Best wishes, Paul.

      --- Garrett Goebel <garrett@...> wrote:
      > How can I have a server side function set related fault
      > information returned to the client?
      >
      > Assume the client has a global fault handler which per the
      > guide will "return undef and setup $! on failure". I.e.:
      >
      > use SOAP::Lite
      > on_fault => sub {
      > my($soap, $res) = @_;
      > eval {
      > die ref $res
      > ? $res->faultdetail
      > : $soap->transport->status
      > };
      > return ref $res ? $res : new SOAP::SOM;
      > };
      >
      >
      > Toss in the following server side functions:
      >
      > sub boom { die "big bad error" }
      > sub kaboom { eval {boom}; defined $! && exit warn "kaboom: $!" }
      >
      >
      > When invoked from the client:
      >
      > $soap->boom()->result();
      > defined $! and print "boom: ", $!, "\n";
      >
      > $soap->kaboom()->result();
      > defined $! and print "kaboom ", $!, "\n";
      >
      >
      > I get the following STDOUT:
      >
      > > server.pl
      > kaboom: at ... line ...
      > >
      >
      > > client.pl
      > boom: Bad file descriptor
      > Can't call method "result" on an undefined value at ... line ...
      > >
      >
      >
      > How do I set meaningful fault detail for the client?
      >
      > I'm assuming all the server functions are being eval'd so in
      > order to short-circuit the execution of the server I must
      > resort to <C>exit</C>.
      >
      > Any other tips or suggestions?
      >


      __________________________________________________
      Do You Yahoo!?
      Yahoo! Auctions - buy the things you want at great prices
      http://auctions.yahoo.com/
    • Show all 13 messages in this topic