WebService::Lucene::Exception - Exceptions to catch from the web service


WebService-Lucene documentation Contained in the WebService-Lucene distribution.

Index


Code Index:

NAME

Top

WebService::Lucene::Exception - Exceptions to catch from the web service

SYNOPSIS

Top

    my $entry = eval { $index->get_document( 1 ); };
    if( my $e = WebService::Lucene::Exception->caught ) {
        # handle exception
    }

DESCRIPTION

Top

Object thrown for all exceptions from the web service.

METHODS

Top

new( $reponse )

Constructs a new exception from an HTTP::Response.

response ( )

The HTTP::Response object passed to this exception.

entry( )

The XML::Atom Entry for the error returned from the server.

stacktrace( )

If debug mode is enabled, a full stracktrace from the server-side will be found here.

type ( )

Returns the type of exception the lucene web service has thrown.

Fields( )

Subclassed method to store an arrayref of extra fields.

AUTHORS

Top

* Brian Cassidy <brian.cassidy@nald.ca>
* Adam Paynter <adam.paynter@nald.ca>

COPYRIGHT AND LICENSE

Top


WebService-Lucene documentation Contained in the WebService-Lucene distribution.
package WebService::Lucene::Exception;

use strict;
use warnings;

use Exception::Class 'WebService::Lucene::Exception' =>
    { fields => [ qw( response entry stacktrace type ) ] };
use base qw( Exception::Class::Base );

use XML::Atom::Entry;

sub new {
    my ( $class, $response ) = @_;
    my $self = $class->SUPER::new;

    $self->{ response } = $response;

    my $entry = eval { XML::Atom::Entry->new( \$response->content ) };

    # if lucene-ws is broken, we won't get an XML::Atom::Entry
    if ( !$entry ) {
        $self->{ message } = $response->message;
        return $self;
    }

    $self->{ entry }   = $entry;
    $self->{ message } = $entry->summary;
    $self->{ type }    = $entry->title;

    my $content = $entry->content;
    if ( $content->type eq 'html' ) {
        $self->{ statcktrace } = $content->body;
    }

    return $self;
}

1;