aboutsummaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
authorJeff Garzik <jeff@garzik.org>2010-12-28 17:13:59 -0500
committerJeff Garzik <jgarzik@redhat.com>2010-12-28 17:13:59 -0500
commit2f9a6deef91afd4c0ef67dc332e39b4fdfb4d3b4 (patch)
treec7d5ebceae94fe2993d5434a091b9a40ae780888 /util.c
parent9e5a173c3845fb7b5d316b0455352a08847b8c23 (diff)
Improve CURL HTTP request error diagnostics.
Diffstat (limited to 'util.c')
-rw-r--r--util.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/util.c b/util.c
index 05c876e..669dd82 100644
--- a/util.c
+++ b/util.c
@@ -90,10 +90,13 @@ json_t *json_rpc_call(const char *url, const char *userpass, const char *rpc_req
json_error_t err = { };
struct curl_slist *headers = NULL;
char len_hdr[64];
+ char curl_err_str[CURL_ERROR_SIZE];
curl = curl_easy_init();
- if (!curl)
+ if (!curl) {
+ fprintf(stderr, "CURL initialization failed, aborting JSON-RPC call\n");
return NULL;
+ }
if (opt_protocol)
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
@@ -105,6 +108,7 @@ json_t *json_rpc_call(const char *url, const char *userpass, const char *rpc_req
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &all_data);
curl_easy_setopt(curl, CURLOPT_READFUNCTION, upload_data_cb);
curl_easy_setopt(curl, CURLOPT_READDATA, &upload_data);
+ curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, curl_err_str);
if (userpass) {
curl_easy_setopt(curl, CURLOPT_USERPWD, userpass);
curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
@@ -127,8 +131,10 @@ json_t *json_rpc_call(const char *url, const char *userpass, const char *rpc_req
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
rc = curl_easy_perform(curl);
- if (rc)
+ if (rc) {
+ fprintf(stderr, "HTTP request failed: %s\n", curl_err_str);
goto err_out;
+ }
val = json_loads(all_data.buf, &err);
if (!val) {