SOAP: The Power Of Simplicity 
O'Reilly P2P Conference 2001
<<< 22/52 >>>
Copyright (C) 2001 Paul Kulchenko, Tony Hong

SOAP::Lite, Basic concepts: Returning Fault

SOAP has it's own fault mechanism using a standard SOAP fault XML envelope.

die is used to return fault on server side:

  
  sub my_method {
    # do something here
    return $result if $everything_is_ok;
    die "Something bad happened\n";
  }

For better control over Fault properties (such as faultcode, faultstring and detail), die with SOAP::Fault as a parameter can be used:

  
  sub die_with_fault {
    die SOAP::Fault->faultcode('Server.Custom')           # Server
                   ->faultstring('Died in server method') # Application error
                   ->faultdetail(bless {code => 1} => 'BadError')
                   ->faultactor('http://www.soaplite.com/custom');
  }
  sub die_with_object {
    die SOAP::Data
      -> name(something => 'value')
      -> uri('http://namespaces.soaplite.com/foobar');
  }