Skip Menu |
 

This queue is for tickets about the JSON-RPC CPAN distribution.

Report information
The Basics
Id: 93242
Status: open
Priority: 0/
Queue: JSON-RPC

People
Owner: Nobody in particular
Requestors: patrick.palmieri2 [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject:
Date: Fri, 21 Feb 2014 16:51:18 -0500
To: bug-JSON-RPC [...] rt.cpan.org
From: Patrick Palmieri <patrick.palmieri2 [...] gmail.com>
Download (untitled) / with headers
text/plain 982b
Hello, When the JSON-RPC HTTP server reports any error, the result is always undef. This is not very usefull if you need to see the error message that is returned from the server. This can be fixed by either removing the if that checks is_sucess, or by adding "JSON::RPC::ReturnObject->new($result, $self->json);" to the else return. example output $VAR1 = bless( { 'version' => 0, 'content' => { 'error' => { 'message' => 'Block not found', 'code' => -5 }, 'id' => undef, 'result' => undef }, 'jsontext' => '{"result":null,"error":{"code":-5,"message":"Block not found"},"id":null} ', 'is_success' => 0 }, 'JSON::RPC::ReturnObject' );
I agree on the general principle. Patches + tests welcome!
Subject: Re: [rt.cpan.org #93242]
Date: Fri, 21 Feb 2014 20:10:08 -0500
To: bug-JSON-RPC [...] rt.cpan.org
From: Patrick Palmieri <patrick.palmieri2 [...] gmail.com>
Download (untitled) / with headers
text/plain 2.5k
The test script does a call against a bitcoind JSON-RPC server. TEST SCRIPT: #!/usr/bin/perl -w use JSON::RPC::Client; use Data::Dumper; $client = new JSON::RPC::Client; $client->ua->credentials( 'localhost:9932', 'jsonrpc', 'user' => 'password' ); $uri = 'http://localhost:9932/'; $obj = { method => 'getblock', params => ['123'] }; $res = $client->call( $uri, $obj ); if ($res){ if ($res->is_error) { $error = $res->error_message; print "Error : ".$error->{'message'}."\n"; } else { print Dumper($res->result); } } else { print "Status: ".$client->status_line."\n"; }; print Dumper($res); SCRIPT OUTPUT: $perl scrap/jsonrpc.pl Error : Block not found $VAR1 = bless( { 'version' => 0, 'content' => { 'error' => { 'message' => 'Block not found', 'code' => -5 }, 'id' => undef, 'result' => undef }, 'jsontext' => '{"result":null,"error":{"code":-5,"message":"Block not found"},"id":null} ', 'is_success' => 0 }, 'JSON::RPC::ReturnObject' ); MODIFCATION TO JSON::RPC::Client The "is_success" defined in HTTP::Status is >= 200 && < 300, so it only counts HTTP codes 200 - 299 as as success. In your original subroutine, if the response code is something other then this, the return is null. Below are my changes to the call subroutine. sub call { my ($self, $uri, $obj) = @_; my $result; if ($uri =~ /\?/) { $result = $self->_get($uri); } else { Carp::croak "not hashref." unless (ref $obj eq 'HASH'); $result = $self->_post($uri, $obj); } my $service = $obj->{method} =~ /^system\./ if ( $obj ); $self->status_line($result->status_line); return unless($result->content); # notification? if ($service) { return JSON::RPC::ServiceObject->new($result, $self->json); } return JSON::RPC::ReturnObject->new($result, $self->json); } Please let me know your thoughts. Patrick Show quoted text
-----Original Message----- From: Daisuke Maki via RT <bug-JSON-RPC@rt.cpan.org> Reply-to: bug-JSON-RPC@rt.cpan.org To: patrick.palmieri2@gmail.com Subject: [rt.cpan.org #93242] Date: Fri, 21 Feb 2014 17:29:57 -0500 <URL: https://rt.cpan.org/Ticket/Display.html?id=93242 > I agree on the general principle. Patches + tests welcome!
Download (untitled) / with headers
text/plain 193b
github pullreq/repo to compare against or whatever is much much appreciated! At least a diff against the current master would do. Sorry to be a bitch here. https://github.com/lestrrat/JSON-RPC
Subject: Re: [rt.cpan.org #93242]
Date: Sat, 22 Feb 2014 10:49:22 -0500
To: bug-JSON-RPC [...] rt.cpan.org
From: Patrick Palmieri <patrick.palmieri2 [...] gmail.com>
Download (untitled) / with headers
text/plain 591b
no problem, i didn't know you had the modules up on github, i'll create a fork, add my changes, and send a pull request. Show quoted text
-----Original Message----- From: Daisuke Maki via RT <bug-JSON-RPC@rt.cpan.org> Reply-to: bug-JSON-RPC@rt.cpan.org To: patrick.palmieri2@gmail.com Subject: [rt.cpan.org #93242] Date: Sat, 22 Feb 2014 03:17:04 -0500 <URL: https://rt.cpan.org/Ticket/Display.html?id=93242 > github pullreq/repo to compare against or whatever is much much appreciated! At least a diff against the current master would do. Sorry to be a bitch here. https://github.com/lestrrat/JSON-RPC


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.