AnyEvent::XMPP::Error::Stanza - Stanza errors


AnyEvent-XMPP documentation Contained in the AnyEvent-XMPP distribution.

Index


Code Index:

NAME

Top

AnyEvent::XMPP::Error::Stanza - Stanza errors

Subclass of AnyEvent::XMPP::Error

METHODS

xml_node ()

Returns the AnyEvent::XMPP::Node object for this Stanza error. This method returns undef if the Stanza timeouted.

In the case of a timeout the condition method returns client-timeout, type returns 'cancel' and code undef.

type ()

This method returns one of:

   'cancel', 'continue', 'modify', 'auth' and 'wait'

code ()

This method returns the error code if one was found.

condition ()

Returns the error condition string if one was found when receiving the Stanza error. It can be undef or one of:

   bad-request
   conflict
   feature-not-implemented
   forbidden
   gone
   internal-server-error
   item-not-found
   jid-malformed
   not-acceptable
   not-allowed
   not-authorized
   payment-required
   recipient-unavailable
   redirect
   registration-required
   remote-server-not-found
   remote-server-timeout
   resource-constraint
   service-unavailable
   subscription-required
   undefined-condition
   unexpected-request




condition_node ()

Returns the error condition node if one was found when receiving the Stanza error. This is mostly for debugging purposes.

text ()

The humand readable error portion. Might be undef if none was received.

AUTHOR

Top

Robin Redeker, <elmex at ta-sa.org>, JID: <elmex at jabber.org>

COPYRIGHT & LICENSE

Top


AnyEvent-XMPP documentation Contained in the AnyEvent-XMPP distribution.
package AnyEvent::XMPP::Error::Stanza;
use AnyEvent::XMPP::Error;
use strict;
our @ISA = qw/AnyEvent::XMPP::Error/;

sub init {
   my ($self) = @_;
   my $node = $self->xml_node;

   unless (defined $node) {
      $self->{error_cond} = 'client-timeout';
      $self->{error_type} = 'cancel';
      return;
   }

   my @error;
   my ($err) = $node->find_all ([qw/client error/]);

   unless ($err) {
      warn "No error element found in error stanza!";
      $self->{text} = "Unknown Stanza error";
      return
   }

   $self->{error_type} = $err->attr ('type');
   $self->{error_code} = $err->attr ('code');

   if (my ($txt) = $err->find_all ([qw/stanzas text/])) {
      $self->{error_text} = $txt->text;
   }

   for my $er (
     qw/bad-request conflict feature-not-implemented forbidden
        gone internal-server-error item-not-found jid-malformed
        not-acceptable not-allowed not-authorized payment-required
        recipient-unavailable redirect registration-required
        remote-server-not-found remote-server-timeout resource-constraint
        service-unavailable subscription-required undefined-condition
        unexpected-request/)
   {
      if (my ($el) = $err->find_all ([stanzas => $er])) {
         $self->{error_cond}      = $er;
         $self->{error_cond_node} = $el;
         last;
      }
   }

   if (not ($self->{error_cond}) && defined $self->{error_code}) {
      for my $er (keys %AnyEvent::XMPP::Writer::STANZA_ERRORS) {
         my $ern = $AnyEvent::XMPP::Writer::STANZA_ERRORS{$er};
         if ($ern->[1] == $self->{error_code} && $ern->[0] eq $self->{error_type}) {
            $self->{error_cond} = $er;
            last;
         }
      }
   }

   if (!(defined $self->{error_code}) && $self->{error_cond}) {
      my $ern = $AnyEvent::XMPP::Writer::STANZA_ERRORS{$self->{error_cond}};
      $self->{error_type} = $ern->[0];
      $self->{error_code} = $ern->[1];
   }
}

sub xml_node {
   $_[0]->{node}
}

sub type { $_[0]->{error_type} }

sub code { $_[0]->{error_code} }

sub condition { $_[0]->{error_cond} }

sub condition_node { $_[0]->{error_cond_node} }

sub text { $_[0]->{error_text} }

sub string {
   my ($self) = @_;

   sprintf "stanza error: %s/%s (type %s): %s",
      $self->code || '',
      $self->condition || '',
      $self->type,
      $self->text
}

1; # End of AnyEvent::XMPP