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.
This commit is contained in:
Joris Vink 2019-05-30 14:25:04 +02:00
parent 88553cd2dd
commit a8aff8b737
3 changed files with 18 additions and 3 deletions

View File

@ -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

View File

@ -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

View File

@ -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);
}