[Bps-public-commit] storage-box branch, improve-error-reporting, created. acf365f565d4e183a4a51be6fb4d3714f676af46
Dave Goehrig
dave at bestpractical.com
Mon Sep 26 12:33:47 EDT 2016
The branch, improve-error-reporting has been created
at acf365f565d4e183a4a51be6fb4d3714f676af46 (commit)
- Log -----------------------------------------------------------------
commit acf365f565d4e183a4a51be6fb4d3714f676af46
Author: Dave Goehrig <dave at bestpractical.com>
Date: Mon Sep 26 12:33:23 2016 -0400
added logging to all requests
diff --git a/LICENSE b/LICENSE
index 02d21b7..119ac90 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,4 +1,4 @@
-This software is copyright (c) 2016- by Dave Goehrig <dave at dloh.org>.
+This software is copyright (c) 2016 by Dave Goehrig <dave at dloh.org>.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
@@ -12,7 +12,7 @@ b) the "Artistic License"
--- The GNU General Public License, Version 1, February 1989 ---
-This software is Copyright (c) 2016- by Dave Goehrig <dave at dloh.org>.
+This software is Copyright (c) 2016 by Dave Goehrig <dave at dloh.org>.
This is free software, licensed under:
@@ -272,7 +272,7 @@ That's all there is to it!
--- The Artistic License 1.0 ---
-This software is Copyright (c) 2016- by Dave Goehrig <dave at dloh.org>.
+This software is Copyright (c) 2016 by Dave Goehrig <dave at dloh.org>.
This is free software, licensed under:
diff --git a/META.json b/META.json
index 11ca7a5..4337340 100644
--- a/META.json
+++ b/META.json
@@ -55,7 +55,7 @@
}
},
"release_status" : "stable",
- "version" : "0.01",
+ "version" : "0.02",
"x_contributors" : [
"Dave Goehrig <dave at bestpractical.com>"
],
diff --git a/README.md b/README.md
index 33e5dc7..13b7b78 100644
--- a/README.md
+++ b/README.md
@@ -123,7 +123,7 @@ Dave Goehrig <dave at dloh.org>
# COPYRIGHT
-Copyright 2016- Dave Goehrig
+Copyright (C) 2016 Dave Goehrig
# LICENSE
diff --git a/lib/Storage/Box.pm b/lib/Storage/Box.pm
index de655e4..1634505 100644
--- a/lib/Storage/Box.pm
+++ b/lib/Storage/Box.pm
@@ -8,8 +8,10 @@ use Storage::Box::Auth;
use Storage::Box::User;
use Storage::Box::File;
use Storage::Box::Folder;
+use Storage::Box::Logger;
our $VERSION = '0.01';
+our $logger = Storage::Box::Logger::logger;
=pod
@@ -56,6 +58,7 @@ has user_id => '';
has enterprise_auth => '';
has user_auth => '';
has user => '';
+has logger => '';
=pod
@@ -91,7 +94,9 @@ sub authenticate_enterprise {
client_id => $self->client_id,
client_secret => $self->client_secret
));
- $self->enterprise_auth->enterprise->request;
+ my $req = $self->enterprise_auth->enterprise->request;
+ $logger->error("Failed to authenticate $self->enterprise_id with code $req->code\n")
+ unless $req->code == 200;
}
$self;
}
@@ -132,7 +137,9 @@ sub authenticate_user {
client_id => $self->client_id,
client_secret => $self->client_secret
));
- $self->user_auth->user->request;
+ my $req = $self->user_auth->user->request;
+ $logger->error("Failed to authenticate user $self->user_id, with code $req->code\n")
+ unless $req->code == 200;
}
$self;
}
@@ -343,7 +350,7 @@ Dave Goehrig E<lt>dave at dloh.orgE<gt>
=head1 COPYRIGHT
-Copyright 2016- Dave Goehrig
+Copyright (C) 2016 Dave Goehrig
=head1 LICENSE
diff --git a/lib/Storage/Box/Auth.pm b/lib/Storage/Box/Auth.pm
index 7c57f1c..e829ac3 100644
--- a/lib/Storage/Box/Auth.pm
+++ b/lib/Storage/Box/Auth.pm
@@ -107,7 +107,8 @@ B<generate_keys($password)>
=cut
sub generate_keys {
- my ($self) = @_;
+ my ($self,$password) = @_;
+ $self->password($password);
$self->generate_private_key;
$self->generate_public_key;
print <<THERE;
diff --git a/lib/Storage/Box/Request.pm b/lib/Storage/Box/Request.pm
index ced0404..3394b11 100644
--- a/lib/Storage/Box/Request.pm
+++ b/lib/Storage/Box/Request.pm
@@ -24,6 +24,7 @@ use Modern::Perl;
use JSON qw/ encode_json decode_json /;
use WWW::Curl::Easy;
use WWW::Curl::Form;
+use Storage::Box::Logger;
has url => '';
has auth => '';
@@ -33,10 +34,14 @@ has form => '';
has max_retries => 5;
has retries => 0;
has code => 200;
+has error => '';
+
+our $logger = Storage::Box::Logger::logger;
sub get {
my $self = shift;
$self->curl( WWW::Curl::Easy->new() ) unless $self->curl;
+ $logger->debug("GET $self->url\n");
$self;
}
@@ -44,6 +49,7 @@ sub post {
my $self = shift;
$self->curl( WWW::Curl::Easy->new() ) unless $self->curl;
$self->curl->setopt(CURLOPT_POST, 1);
+ $logger->debug("POST $self->url\n");
$self;
}
@@ -51,6 +57,7 @@ sub put {
my $self = shift;
$self->curl( WWW::Curl::Easy->new() ) unless $self->curl;
$self->curl->setopt(CURLOPT_CUSTOMREQUEST,"PUT");
+ $logger->debug("PUT $self->url\n");
$self;
}
@@ -58,15 +65,18 @@ sub delete {
my $self = shift;
$self->curl( WWW::Curl::Easy->new() ) unless $self->curl;
$self->curl->setopt(CURLOPT_CUSTOMREQUEST,"DELETE");
+ $logger->debug("DELETE $self->url\n");
$self;
}
sub request {
my $self = shift;
$self->curl( WWW::Curl::Easy->new() ) unless $self->curl;
+ my $auth = $self->auth->token();
+ $self->warn("No authorization token for request $self->url") unless $auth;
my $headers = [
"Accept: */*",
- "Authorization: Bearer " . $self->auth->token()
+ "Authorization: Bearer " . $auth
];
my $body;
$self->curl->setopt(CURLOPT_FOLLOWLOCATION,1);
@@ -75,16 +85,20 @@ sub request {
$self->curl->setopt(CURLOPT_URL,$self->url);
$self->curl->setopt(CURLOPT_HTTPPOST,$self->form) if ($self->form ne '');
if ($self->curl->perform) { # CURLE_OK is 0
+ $logger->warn("Curl to $self->url failed, retrying $self->retries\n");
if ( ++$self->retries < $self->max_retries) {
sleep 1;
return $self->request;
}
+ $logger->error("Curl exceeded max tries to $self->url\n");
$self->retries(0);
$self->body(''); # fail with empty body
return $self;
}
$self->code($self->curl->getinfo(CURLINFO_RESPONSE_CODE));
+ $logger->info("Request to $self->url returned status $self->code\n");
$self->body($body);
+ $logger->debug("Response: $self->body\n");
$self;
}
-----------------------------------------------------------------------
More information about the Bps-public-commit
mailing list