DAWN-84 ⁃ Add better error handling/messages to push transaction
Currently, the error messages returned from push transaction are not proper JSON. The error messages need to be improved, error codes added, and JSON structure defined.
Work with the WebUI team to determine best user experience.
ATC:
On an eosd with the http_plugin enabled, use curl to exercise the http support. Compose intentionally bad GET and POST queries to trigger 404 and 500 errors in the server and verify that the error returned contains the "Content-type" header with a value of "application/json" and that the body of the response is valid JSON format.
Sample curl command to trigger 404:
curl -D -0 -v "http://127.0.0.1:8888/v1/chain/get_inf"
➤ Kevin Heifner commented:
Outline of better error generation at the end of this document. https://docs.google.com/document/d/1E6BQVX1E8jsCzJIpFWV_B3hfA7Br6iiFlUiWZJpJ3zM/edit#
Need to improve http_plugin with correct error codes and formatted json error responds. Update eosc and eosd_run_test.sh as needed.
➤ Jonathan Giszczak commented:
Incorporated response code 202 into Chain API as appropriate. Still need to revise wallet and account history plugins as needed.
➤ Jonathan Giszczak commented:
Incorporated response code 201 into Wallet API as appropriate. Account history plugin required no changes.
Resolved by #628.
➤ Joshua Lavin commented:
There is no test plan on this issue; cannot be tested.
➤ Andrianto Lie commented:
Checked for the following HTTP Status Code
- 200 OK
- 202 Accepted
- 400 Bad Request
- 401 Unauthorized
- 404 Not Found
- 409 Conflict
- 500 Internal Service Error
That their response's header is Content-type: application/json and has valid JSON response in form of
{ "code": 404, "message": "Not found" “details”: “a more detailed string “ }
➤ Andrianto Lie commented:
Details:
200 OK Command:
curl -v http://localhost:8888/v1/chain/get_block -d '{"block_num_or_id":1}'Result:
- Trying ::1...
- TCP_NODELAY set
- Trying 127.0.0.1...
- TCP_NODELAY set
- Connected to localhost (127.0.0.1) port 8888 (#0)
POST /v1/chain/get_block HTTP/1.1 Host: localhost:8888 User-Agent: curl/7.54.0 Accept: / Content-Length: 21 Content-Type: application/x-www-form-urlencoded
- upload completely sent off: 21 out of 21 bytes < HTTP/1.1 200 OK < Content-Length: 527 < Content-type: application/json < Server: WebSocket++/0.7.0 <
- Connection #0 to host localhost left intact {"previous":"0000000000000000000000000000000000000000000000000000000000000000","timestamp":"2017-11-14T16:45:27","transaction_merkle_root":"0000000000000000000000000000000000000000000000000000000000000000","producer":"inita","producer_changes":[],"producer_signature":"1f26d13747a74bd5726739d764aff85c30f3ebef21de1ddbc3bb5646dfb8a3fa754cd98776bdec79b610b03b40167a60cb9b7b08cdd905124888e0c98fb436dc76","cycles":[],"id":"00000001b7efdf23106f09d329b03d2b459629fc8a25f4977644f96ac55d2947","block_num":1,"refBlockPrefix":3540610832}202 Accepted Command:
curl -v http://localhost:8888/v1/chain/push_transaction -d '{"ref_block_num":3834,"ref_block_prefix":3698636732,"expiration":"2017-11-16T04:28:49","scope":["initb","initc"],"read_scope":[],"messages":[{"code":"eos","type":"transfer","authorization":[{"account":"initb","permission":"active"}],"data":"000000008093dd74000000000094dd74e80300000000000000"}],"signatures":["1f775557e49b4142d1cd22882fafef3cdcbfbbff6e2bf662a2e5c0b1c9beb11fba35c9b195fe01407b14680d8d11e8b3bb7f755877343152f2c3b070dc9dd555c5"]}'Result:
- Trying ::1...
- TCP_NODELAY set
- Trying 127.0.0.1...
- TCP_NODELAY set
- Connected to localhost (127.0.0.1) port 8888 (#0)
POST /v1/chain/push_transaction HTTP/1.1 Host: localhost:8888 User-Agent: curl/7.54.0 Accept: / Content-Length: 443 Content-Type: application/x-www-form-urlencoded
- upload completely sent off: 443 out of 443 bytes < HTTP/1.1 202 Accepted < Content-Length: 751 < Content-type: application/json < Server: WebSocket++/0.7.0 <
- Connection #0 to host localhost left intact {"transaction_id":"92039cb1c98bd00058b1296b4c99f1b10be1fa0c65efbbad879bc0c07e20c27d","processed":{"ref_block_num":3834,"ref_block_prefix":3698636732,"expiration":"2017-11-16T04:28:49","scope":["initb","initc"],"signatures":["1f775557e49b4142d1cd22882fafef3cdcbfbbff6e2bf662a2e5c0b1c9beb11fba35c9b195fe01407b14680d8d11e8b3bb7f755877343152f2c3b070dc9dd555c5"],"messages":[{"code":"eos","type":"transfer","authorization":[{"account":"initb","permission":"active"}],"data":{"from":"initb","to":"initc","amount":1000,"memo":""},"hex_data":"000000008093dd74000000000094dd74e80300000000000000"}],"output":[{"notify":[{"name":"initc","output":{"notify":[],"deferred_trxs":[]}},{"name":"initb","output":{"notify":[],"deferred_trxs":[]}}],"deferred_trxs":[]}]}}400 Bad Request Command:
curl -v http://localhost:8888/v1/chain/get_block -d '{}'Result:
- Trying ::1...
- TCP_NODELAY set
- Trying 127.0.0.1...
- TCP_NODELAY set
- Connected to localhost (127.0.0.1) port 8888 (#0)
POST /v1/chain/get_block HTTP/1.1 Host: localhost:8888 User-Agent: curl/7.54.0 Accept: / Content-Length: 2 Content-Type: application/x-www-form-urlencoded
- upload completely sent off: 2 out of 2 bytes < HTTP/1.1 400 Bad Request < Content-Length: 93 < Content-type: application/json < Server: WebSocket++/0.7.0 <
- Connection #0 to host localhost left intact {"code":400,"message":"Bad Request","details":"End Of File (11)\nunexpected end of file\n\n"}401 Unauthorized Command:
curl -v http://localhost:8888/v1/chain/push_transaction -d '{"ref_block_num":"100","ref_block_prefix":"137469861","expiration":"2017-11-16T12:28:49","scope":["initb","initc"],"messages":[{"code":"eos","type":"transfer","authorization":[{"account":"initb","permission":"active"}],"data":"000000008093dd74000000000094dd74e80300000000000000"}],"signatures":[],"authorizations":[]}'Result:
- Trying ::1...
- TCP_NODELAY set
- Trying 127.0.0.1...
- TCP_NODELAY set
- Connected to localhost (127.0.0.1) port 8888 (#0)
POST /v1/chain/push_transaction HTTP/1.1 Host: localhost:8888 User-Agent: curl/7.54.0 Accept: / Content-Length: 317 Content-Type: application/x-www-form-urlencoded
- upload completely sent off: 317 out of 317 bytes < HTTP/1.1 401 Unauthorized < Content-Length: 235 < Content-type: application/json < Server: WebSocket++/0.7.0 <
- Connection #0 to host localhost left intact {"code":401,"message":"UnAuthorized","details":"signatures do not satisfy declared authorizations (3030002)\nTransaction declares authority '{"account":"initb","permission":"active"}', but does not have signatures for it.\n\n"}404 Not Found Command:
curl -v http://localhost:8888/v1/chain/get_infResult:
- Trying ::1...
- TCP_NODELAY set
- Trying 127.0.0.1...
- TCP_NODELAY set
- Connected to localhost (127.0.0.1) port 8888 (#0)
GET /v1/chain/get_inf HTTP/1.1 Host: localhost:8888 User-Agent: curl/7.54.0 Accept: /
< HTTP/1.1 404 Not Found < Content-Length: 63 < Content-type: application/json < Server: WebSocket++/0.7.0 <
- Connection #0 to host localhost left intact {"code":404,"message":"Not Found","details":"Unknown Endpoint"}409 Conflict Command (exactly the same as command used to test 202 Accepted above):
curl -v http://localhost:8888/v1/chain/push_transaction -d '{"ref_block_num":3834,"ref_block_prefix":3698636732,"expiration":"2017-11-16T04:28:49","scope":["initb","initc"],"read_scope":[],"messages":[{"code":"eos","type":"transfer","authorization":[{"account":"initb","permission":"active"}],"data":"000000008093dd74000000000094dd74e80300000000000000"}],"signatures":["1f775557e49b4142d1cd22882fafef3cdcbfbbff6e2bf662a2e5c0b1c9beb11fba35c9b195fe01407b14680d8d11e8b3bb7f755877343152f2c3b070dc9dd555c5"]}'Result:
- Trying ::1...
- TCP_NODELAY set
- Trying 127.0.0.1...
- TCP_NODELAY set
- Connected to localhost (127.0.0.1) port 8888 (#0)
POST /v1/chain/push_transaction HTTP/1.1 Host: localhost:8888 User-Agent: curl/7.54.0 Accept: / Content-Length: 443 Content-Type: application/x-www-form-urlencoded
- upload completely sent off: 443 out of 443 bytes < HTTP/1.1 409 Conflict < Content-Length: 112 < Content-type: application/json < Server: WebSocket++/0.7.0 <
- Connection #0 to host localhost left intact {"code":409,"message":"Conflict","details":"duplicate transaction (3030011)\nTransaction is not unique\n\n\n\n"}500 Internal Service Error Command:
curl -v http://localhost:8888/v1/chain/get_block -d '{"block_num_or_id":"a"}'Result:
- Trying ::1...
- TCP_NODELAY set
- Trying 127.0.0.1...
- TCP_NODELAY set
- Connected to localhost (127.0.0.1) port 8888 (#0)
POST /v1/chain/get_block HTTP/1.1 Host: localhost:8888 User-Agent: curl/7.54.0 Accept: / Content-Length: 23 Content-Type: application/x-www-form-urlencoded
- upload completely sent off: 23 out of 23 bytes < HTTP/1.1 500 Internal Server Error < Content-Length: 266 < Content-type: application/json < Server: WebSocket++/0.7.0 <
- Connection #0 to host localhost left intact {"code":500,"message":"Internal Service Error","details":"4 parse_error_exception: Parse Error\nUnexpected char '97' in "a"\n {"c":97,"s":"a"}\n thread-0 json.cpp:431 variant_from_stream\n\n {"str":"a"}\n thread-0 json.cpp:476 from_string"}
➤ Andrianto Lie commented:
This document https://docs.google.com/document/d/1E6BQVX1E8jsCzJIpFWV_B3hfA7Br6iiFlUiWZJpJ3zM/edit# mentions that the error JSON format should be
{
"code": 404, // should match “Actual” HTTP response code
"message": "Not found"
“details”: “a more detailed string “,
“stack”: [“line1”,”line2”, ...]
}Compared to the current implementation where there is no stack field
{
"code": 404, // should match “Actual” HTTP response code
"message": "Not found"
“details”: “a more detailed string “
}Is this intended change of specification? Or is the stack field not implemented yet? Please advise [~jonathan.giszczak] If it is the former than the QA passes. Thanks!
➤ Bezwada Satyapravin commented:
Apologies for moving it back but I want to test the complete API not just get block or get info (including messages and transactions) but don't have the knowledge to build the JSONs for it. Kindly provide examples. Also I think this test can be automated.
➤ Jonathan Giszczak commented:
[~andrianto.lie]
Supporting a stack field is expensive and difficult enough that I intentionally omitted it. It may be added at some later date.