mirror of https://git.kore.io/kore.git
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:
parent
88553cd2dd
commit
a8aff8b737
|
@ -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
|
||||
|
|
17
src/curl.c
17
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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue