kore

a fork of the worlds most advanced web framework
Log | Files | Refs | README | LICENSE

commit a8aff8b73793cff09f1e7f26253d6c9290cd2eec
parent 88553cd2dd03b34db988e25772691085c4929482
Author: Joris Vink <joris@coders.se>
Date:   Thu, 30 May 2019 14:25:04 +0200

Improve curl error string handling.

Introduce kore_curl_strerror(), use this in kore_curl_logerror()
instead of assuming our errbuf has been populated.

Also use it in the python httpclient when throwing an exception rather
then looking at the errbuf member which may or may not be empty.

Diffstat:
Minclude/kore/curl.h | 2++
Msrc/curl.c | 17+++++++++++++++--
Msrc/python.c | 2+-
3 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/include/kore/curl.h b/include/kore/curl.h @@ -91,6 +91,8 @@ void kore_curl_bind_request(struct kore_curl *, struct http_request *); void kore_curl_bind_callback(struct kore_curl *, void (*cb)(struct kore_curl *, void *), void *); +const char *kore_curl_strerror(struct kore_curl *); + #if defined(__cplusplus) } #endif diff --git a/src/curl.c b/src/curl.c @@ -244,11 +244,24 @@ kore_curl_success(struct kore_curl *client) return (client->result == CURLE_OK); } +const char * +kore_curl_strerror(struct kore_curl *client) +{ + const char *err; + + if (client->errbuf[0] != '\0') + err = &client->errbuf[0]; + else + err = curl_easy_strerror(client->result); + + return (err); +} + void kore_curl_logerror(struct kore_curl *client) { - kore_log(LOG_NOTICE, "curl error: %s -> %s", - client->url, client->errbuf); + kore_log(LOG_NOTICE, "curl error: %s -> %s", client->url, + kore_curl_strerror(client)); } void diff --git a/src/python.c b/src/python.c @@ -4329,7 +4329,7 @@ pyhttp_client_op_iternext(struct pyhttp_client_op *op) if (!kore_curl_success(&op->curl)) { PyErr_Format(PyExc_RuntimeError, "request to '%s' failed: %s", - op->curl.url, op->curl.errbuf); + op->curl.url, kore_curl_strerror(&op->curl)); return (NULL); }