diff --git a/components/esp_http_client/esp_http_client.c b/components/esp_http_client/esp_http_client.c index d54558ec161..779ccf207c9 100644 --- a/components/esp_http_client/esp_http_client.c +++ b/components/esp_http_client/esp_http_client.c @@ -1155,6 +1155,14 @@ int esp_http_client_get_errno(esp_http_client_handle_t client) return esp_transport_get_errno(client->transport); } +esp_err_t esp_http_client_get_and_clear_last_tls_error(esp_http_client_handle_t client, int *tls_code, int *tls_flags){ + if (!client) { + ESP_LOGE(TAG, "Invalid client handle"); + return ESP_FAIL; + } + return esp_tls_get_and_clear_last_error(esp_transport_get_error_handle(client->transport), tls_code, tls_flags); +} + esp_err_t esp_http_client_set_method(esp_http_client_handle_t client, esp_http_client_method_t method) { client->connection_info.method = method; diff --git a/components/esp_http_client/include/esp_http_client.h b/components/esp_http_client/include/esp_http_client.h index 86274bdae51..539992cb159 100644 --- a/components/esp_http_client/include/esp_http_client.h +++ b/components/esp_http_client/include/esp_http_client.h @@ -457,6 +457,23 @@ esp_err_t esp_http_client_set_user_data(esp_http_client_handle_t client, void *d */ int esp_http_client_get_errno(esp_http_client_handle_t client); +/** + * @brief Returns last error in esp_tls with detailed mbedtls related error codes. + * The error information is cleared internally upon return + * + * @param[in] client The esp_http_client handle + * @param[out] esp_tls_error_code last error code returned from mbedtls api (set to zero if none) + * This pointer could be NULL if caller does not care about esp_tls_code + * @param[out] esp_tls_flags last certification verification flags (set to zero if none) + * This pointer could be NULL if caller does not care about esp_tls_code + * + * @return + * - ESP_FAIL if invalid parameters + * - ESP_OK (0) if no error occurred + * - specific error code (based on ESP_ERR_ESP_TLS_BASE) otherwise + */ +esp_err_t esp_http_client_get_and_clear_last_tls_error(esp_http_client_handle_t client, int *esp_tls_error_code, int *esp_tls_flags); + /** * @brief Set http request method *