Skip to content
Snippets Groups Projects
Commit 7977e5ac authored by Síle Ekaterin Liszka's avatar Síle Ekaterin Liszka
Browse files

Chessa::Bug::Adelie: error-handling, bitch

parent 8322374f
No related branches found
No related tags found
No related merge requests found
......@@ -22,6 +22,7 @@ sub new($class, $http, $log, $msg, $conf) {
$self->{msg} = $msg;
$self->{conf} = $conf;
$self->{irc} = $self->{conf}{irc};
$self->{http} = $http;
$self->{projects} = {};
load_projects($self, $http, 'https://git.adelielinux.org/api/v4/projects');
......@@ -40,12 +41,11 @@ sub error($self, $msg, $on_info=undef, $errors=0) {
$self->log($msg, $on_info, $errors);
}
sub load_projects($self, $http, $uri) {
$http->do_request(
sub load_projects($self, $uri) {
$self->{http}->do_request(
uri => $uri,
on_response => sub ($response) {
$self->{log}("Fetched projects from $uri");
projects($self, $http, $response);
projects($self, $response);
}, on_error => sub ($error) {
$self->{log}("Couldn't fetch projects: $error");
croak $error;
......@@ -53,12 +53,11 @@ sub load_projects($self, $http, $uri) {
);
}
sub projects($self, $http, $response) {
sub projects($self, $response) {
my $json = JSON::MaybeXS->new->utf8->decode($response->decoded_content);
for my $item (@{ $json }) {
$self->{projects}{$item->{path_with_namespace}} = $item->{id};
$self->{log}($item->{path_with_namespace} . ' = ' . $item->{id});
}
my $link = $response->header('Link');
my @links = split /, /, $link;
......@@ -66,7 +65,7 @@ sub projects($self, $http, $response) {
if ($i =~ /"next"$/) {
$i =~ /<(.*?)>/;
$link = $1;
load_projects($self, $http, $link);
load_projects($self, $link);
last;
}
}
......@@ -79,7 +78,7 @@ sub wants($self, $project) {
return 0;
}
sub handle($self, $http, $on_info, $data, $errors) {
sub handle($self, $on_info, $data, $errors) {
my ($project, $num, $type) = @{$data};
$self->log("Got $project $type $num");
......@@ -110,7 +109,7 @@ sub handle($self, $http, $on_info, $data, $errors) {
$base .= "$type/$num";
$self->log("Requesting $base");
$http->do_request(
$self->{http}->do_request(
uri => $base,
on_response => sub ($response) {
$func->($self, $response, $on_info, $data, $errors);
......@@ -125,6 +124,11 @@ sub issue($self, $response, $on_info, $data, $errors) {
my $json = JSON::MaybeXS->new->utf8->decode($response->decoded_content);
if (!$response->is_success) {
$self->{log}($self->{msg}('Error', $json->{message}), $on_info, $errors);
return;
}
my %d = (
author => $json->{author}{name} . ' (@' . $json->{author}{username} . ')',
title => $json->{title},
......@@ -144,6 +148,11 @@ sub mr($self, $response, $on_info, $data, $errors) {
my $json = JSON::MaybeXS->new->utf8->decode($response->decoded_content);
if (!$response->is_success) {
$self->{log}($self->{msg}('Error', $json->{message}), $on_info, $errors);
return;
}
my %d = (
author => $json->{author}{name} . ' (@' . $json->{author}{username} . ')',
title => $json->{title},
......@@ -182,6 +191,11 @@ sub commit($self, $response, $on_info, $data, $errors) {
my $json = JSON::MaybeXS->new->utf8->decode($response->decoded_content);
if (!$response->is_success) {
$self->{log}($self->{msg}('Error', $json->{message}), $on_info, $errors);
return;
}
my %d = (
author => $json->{author_name} . ' <' . $json->{author_email} . '>',
commit => $json->{committer_name} . ' <' . $json->{committer_email} . '>',
......@@ -203,6 +217,11 @@ sub snippet($self, $response, $on_info, $data, $errors) {
my $json = JSON::MaybeXS->new->utf8->decode($response->decoded_content);
if (!$response->is_success) {
$self->{log}($self->{msg}('Error', $json->{message}), $on_info, $errors);
return;
}
my %d = (
author => $json->{author}{name} . ' (@' . $json->{author}{username} . ')',
title => $json->{title},
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment