Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
ensure request callback triggers condvar
  • Loading branch information
haarg committed Mar 3, 2014
1 parent 27a2e2b commit fdb34d2
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions lib/MetaCPAN/Web/Model/API.pm
Expand Up @@ -72,22 +72,27 @@ sub request {

$self->client->request($request)->cv->cb(
sub {
my ( $response, $stats ) = shift->recv;
if ( !$response ) {
$req->croak("bad response when requesting " . $request->uri);
return;
};
my $content_type = $response->header('content-type') || '';
my $data = $response->content;

if ( $content_type =~ /^application\/json/ ) {
my $json = eval { decode_json($data) };
$req->send( $@ ? $self->raw_api_response($data) : $json );
}
else {
# Response is raw data, e.g. text/plain
$req->send( $self->raw_api_response($data) );
try {
my ( $response, $stats ) = shift->recv;
if ( !$response ) {
$req->croak("bad response when requesting " . $request->uri);
return;
};
my $content_type = $response->header('content-type') || '';
my $data = $response->content;

if ( $content_type =~ /^application\/json/ ) {
my $json = eval { decode_json($data) };
$req->send( $@ ? $self->raw_api_response($data) : $json );
}
else {
# Response is raw data, e.g. text/plain
$req->send( $self->raw_api_response($data) );
}
}
catch {
$req->croak($_);
};
}
);
return $req;
Expand Down

0 comments on commit fdb34d2

Please sign in to comment.