Bitcoin Forum
September 30, 2016, 01:28:43 PM *
News: Due to DDoS attacks, there may be periodic downtime.
 
   Home   Help Search Donate Login Register  
Pages: [1]
  Print  
Author Topic: HTTP status codes from the JSON-RPC api  (Read 4792 times)
Gavin Andresen
Legendary
*
qt
Offline Offline

Activity: 1652


Chief Scientist


View Profile WWW
September 01, 2010, 08:28:15 PM
 #1

I just submitted a patch to Satoshi to make bitcoin follow the JSON RPC over HTTP spec, and to use the standardized error codes from the JSON-RPC 1.1/2.0 specs.

If you talk directly to bitcoin via JSON-RPC calls, you might need to change your code to recognize the new HTTP status codes and the new format for the 'error' member of the JSON response.  For example:

BEFORE, send {"id":"123", "method": "nosuchmethod", "params": [] } , get response:
Code:
HTTP/1.1 500 Internal Server Error
...

{"result":null,"error":"Method not found.","id":"123"}
AFTER:
Code:
HTTP/1.1 404
...

{"result":null,"error":{"code":-32601,"message":"Method not found"},"id":"123"}

I also removed the broken 'Batch' support, to simplify the code.  I had JSON-RPC-2.0 batch support working properly, but backed those changes out because JSON-RPC 2.0 is way too cutting-edge for bitcoin to support right now (none of the JSON-RPC glue libraries support it yet, and the spec is still changing a bit).

How often do you get the chance to work on a potentially world-changing project?
1475242123
Hero Member
*
Offline Offline

Posts: 1475242123

View Profile Personal Message (Offline)

Ignore
1475242123
Reply with quote  #2

1475242123
Report to moderator
1475242123
Hero Member
*
Offline Offline

Posts: 1475242123

View Profile Personal Message (Offline)

Ignore
1475242123
Reply with quote  #2

1475242123
Report to moderator
1475242123
Hero Member
*
Offline Offline

Posts: 1475242123

View Profile Personal Message (Offline)

Ignore
1475242123
Reply with quote  #2

1475242123
Report to moderator
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
1475242123
Hero Member
*
Offline Offline

Posts: 1475242123

View Profile Personal Message (Offline)

Ignore
1475242123
Reply with quote  #2

1475242123
Report to moderator
Gavin Andresen
Legendary
*
qt
Offline Offline

Activity: 1652


Chief Scientist


View Profile WWW
September 06, 2010, 07:18:04 PM
 #2

Speak now about this change or forever hold your peace...  Satoshi will be including this functionality in the next version of Bitcoin (0.3.12).

If you use the JSON-RPC api, you should check your error-condition-handling code; again, the changes are that the error member will be an Object (with 'code' and 'message' fields) instead of a String, and the HTTP status code may be 404 instead of 500 for method-not-found.

How often do you get the chance to work on a potentially world-changing project?
satoshi
Founder
Sr. Member
*
qt
Offline Offline

Activity: 364


View Profile
September 06, 2010, 09:21:21 PM
 #3

This is in SVN rev 147.

This is more standard, and although json-rpc 1.0 didn't specify the format of error objects, it did specify that they would be objects not strings or other values, so we needed to change this to be correct.  The code/message members have become standard in later json-rpc specs.

If you have code that checks the error and expects a string, you'll need to change it.  When there is an error, the error member is now an object not a string.

Also in SVN rev 147:
- The command line json-rpc returns the error code as its exit code.  Exit codes can only be 0-255 on unix, so it's abs(code)%256.
- The "backupwallet <destination>" command that was discussed in another thread.  It locks the wallet and copies it, so you can be sure you get a correct copy.
nelisky
Legendary
*
Offline Offline

Activity: 1554


View Profile
September 06, 2010, 09:26:10 PM
 #4

This is in SVN rev 147.

This is more standard, and although json-rpc 1.0 didn't specify the format of error objects, it did specify that they would be objects not strings or other values, so we needed to change this to be correct.  The code/message members have become standard in later json-rpc specs.

If you have code that checks the error and expects a string, you'll need to change it.  When there is an error, the error member is now an object not a string.

Also in SVN rev 147:
- The command line json-rpc returns the error code as its exit code.  Exit codes can only be 0-255 on unix, so it's abs(code)%256.
- The "backupwallet <destination>" command that was discussed in another thread.  It locks the wallet and copies it, so you can be sure you get a correct copy.


Woot, double thumbs up on this. Great work, satoshi!
Pages: [1]
  Print  
 
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!