aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStruan Donald <struan@exo.org.uk>2011-11-18 14:31:22 +0000
committerStruan Donald <struan@exo.org.uk>2011-11-18 14:31:22 +0000
commit44091a00e14828f4fff918f9dbdfadef4c04ec11 (patch)
tree2df2773021b5aac933f72a88be73ef879e5851dc
parent6fcada7050449a2181a73fda444b2f2c7ec94236 (diff)
more verbose error messages for open311
-rw-r--r--perllib/Open311.pm16
-rw-r--r--t/open311.t20
2 files changed, 32 insertions, 4 deletions
diff --git a/perllib/Open311.pm b/perllib/Open311.pm
index 4ce867852..e26e3e4c6 100644
--- a/perllib/Open311.pm
+++ b/perllib/Open311.pm
@@ -14,6 +14,8 @@ has test_mode => ( is => 'ro', isa => 'Bool' );
has test_uri_used => ( is => 'rw', 'isa' => 'Str' );
has test_get_returns => ( is => 'rw' );
has endpoints => ( is => 'rw', default => sub { { services => 'services.xml', requests => 'requests.xml' } } );
+has debug => ( is => 'ro', isa => 'Bool', default => 0 );
+has debug_details => ( is => 'rw', 'isa' => 'Str', default => '' );
sub get_service_list {
my $self = shift;
@@ -93,7 +95,7 @@ EOT
}
}
- warn sprintf( "Failed to submit problem %s over Open311, response\n: %s", $problem->id, $response );
+ warn sprintf( "Failed to submit problem %s over Open311, response\n: %s\n%s", $problem->id, $response, $self->debug_details );
return 0;
}
}
@@ -138,6 +140,8 @@ sub _get {
$uri->path( $uri->path . $path );
$uri->query_form( $params );
+ $self->debug_details( $self->debug_details . "\nrequest:" . $uri->as_string );
+
my $content;
if ( $self->test_mode ) {
$content = $self->test_get_returns->{ $path };
@@ -164,14 +168,20 @@ sub _post {
%{ $params }
];
+ $self->debug_details( $self->debug_details . "\nrequest:" . $req->as_string );
+
my $ua = LWP::UserAgent->new();
my $res = $ua->request( $req );
if ( $res->is_success ) {
return $res->decoded_content;
} else {
- warn "request failed: " . $res->status_line;
- warn $self->_process_error( $res->decoded_content );
+ warn sprintf(
+ "request failed: %s\nerror: %s\n%s",
+ $res->status_line,
+ $self->_process_error( $res->decoded_content ),
+ $self->debug_details
+ );
return 0;
}
}
diff --git a/t/open311.t b/t/open311.t
index f7a8cd815..ce4330b9c 100644
--- a/t/open311.t
+++ b/t/open311.t
@@ -2,7 +2,9 @@
use strict;
use warnings;
-use Test::More tests => 4;
+use Test::More;
+use Test::Warn;
+use FixMyStreet::App;
use FindBin;
use lib "$FindBin::Bin/../perllib";
@@ -21,4 +23,20 @@ EOT
is $o->_process_error( $err_text ), "400: Service Code cannot be null -- can't proceed with the request.\n", 'error text parsing';
is $o->_process_error( '503 - service unavailable' ), 'unknown error', 'error text parsing of bad error';
+my $o2 = Open311->new( endpoint => 'http://192.168.50.1/open311/', jurisdiction => 'example.org' );
+my $u = FixMyStreet::App->model('DB::User')->new( { email => 'test@example.org', name => 'A User' } );
+
+my $p = FixMyStreet::App->model('DB::Problem')->new( {
+ latitude => 1,
+ longitude => 1,
+ title => 'title',
+ detail => 'detail',
+ user => $u,
+} );
+
+my $expected_error = qr{.*request failed: 500 Can.t connect to 192.168.50.1:80 \(Operation timed out\).*};
+
+warning_like {$o2->send_service_request( $p, { url => 'http://example.com/' }, 1 )} $expected_error, 'warning generated on failed call';
+
+done_testing();