-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Adds HTTP/1.1 support on cleos requests and improves response handling #9349
Conversation
programs/cleos/httpc.cpp
Outdated
if( print_response ) { | ||
std::cerr << "RESPONSE:" << std::endl | ||
<< "---------------------" << std::endl | ||
<< fc::json::to_pretty_string( response_result ) << std::endl | ||
<< re << std::endl |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why remove the pretty print of the response? The point is to make this human readable. Do you need to parse this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, this does remove the forced pretty-printing of the json and instead relies on the service endpoints choice of formatting which may be very efficient and less readable as a result.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason was because we don't know if it was a successful response so far and we might just dump the response if it's a useful plain text error...
For example, for the PR root problem the status code 426 does not give any json... I imagine there are other handful errors that could either not be a json and have a plain text or have no response at all.
Do you think we should do some checks and prettify if it's a valid json?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe that fc::json::to_pretty_string
will print invalid json just fine. Did you find something where information was lost?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue was the call to fc::json::from_string
can throw an exception and prevent the response from being printed out.
One option is to still try the from_string
anyway, catch any exception, and in the case of exception print a non-pretty response, otherwise it can make response_result
pretty and print that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh thank you @heifner 💯💯💯 -- I was going to go back here and do that as soon as I have a chance but I got stuck in other high priority items!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@heifner Change looks fine to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm. Actually, under some status codes, this now could either return a null variant or it would throw an alternative exception as it tries to convert the null variant to some other type.
Do we want to rethrow the original exception after printing the response if it is null?
Change Description
--print-response
if unable to convert to variantChange Type
Consensus Changes
API Changes
Documentation Additions