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

on_fault error handling

Expand Messages
  • jaykota
    Hi. I am trying to use SOAP Lite to connect to a wsdl service in some perl code. However the on_fault handlers are not working for me. What am I doing wrong or
    Message 1 of 2 , Aug 30, 2004
    • 0 Attachment
      Hi.

      I am trying to use SOAP Lite to connect to a wsdl service in some perl
      code. However the on_fault handlers are not working for me. What am I
      doing wrong or what should I do to fix it?

      The code snipet is below:

      use SOAP::Lite;

      ...

      my $wsdl = "http://${server}/Manager?wsdl";
      my $soap_service = SOAP::Lite
      -> service("$wsdl");
      -> on_fault (sub {
      print "ERROR: Server is not available.\n";
      exit;
      });

      If there is no server currently running I receive the following
      statement:
      Service description 'http://**server**/Manager?wsdl' can't be loaded:
      500 Can't connect to **server** (Connection refused)

      I want the perl code to print my message instead of the error
      statement.

      Thanks,
      Jay
    • Duncan Cameron
      ... The purpose of the on_fault handler is to handle SOAP faults generated by the server. From what I remember the 500 error is generated by the client, the
      Message 2 of 2 , Aug 30, 2004
      • 0 Attachment
        On 2004-08-30 at 19:04:33 jaykota <jaykota@...> wrote:

        >Hi.
        >
        >I am trying to use SOAP Lite to connect to a wsdl service in some perl
        >code. However the on_fault handlers are not working for me. What am I
        >doing wrong or what should I do to fix it?
        >
        >The code snipet is below:
        >
        >use SOAP::Lite;
        >
        >...
        >
        >my $wsdl = "http://${server}/Manager?wsdl";
        >my $soap_service = SOAP::Lite
        > -> service("$wsdl");
        > -> on_fault (sub {
        > print "ERROR: Server is not available.\n";
        > exit;
        > });
        >
        >If there is no server currently running I receive the following
        >statement:
        >Service description 'http://**server**/Manager?wsdl' can't be loaded:
        >500 Can't connect to **server** (Connection refused)

        The purpose of the on_fault handler is to handle SOAP faults generated by the server. From what I remember the 500 error is generated by the client, the LWP::UserAgent module I think.
        To catch client-side errors you will need to wrap your call inside an eval{} and then test $@, e.g.

        eval {
        $r = $s->somemethod();
        };

        if ($@) {
        print "Got exception:\n$@";
        exit;
        }

        Regards
        Duncan
      Your message has been successfully submitted and would be delivered to recipients shortly.