mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
esp_http_client: Support HTTP_EVENT_ERROR event
Closes https://github.com/espressif/esp-idf/issues/7280
This commit is contained in:
parent
8494ef1401
commit
981287900e
@ -994,6 +994,7 @@ int esp_http_client_read(esp_http_client_handle_t client, char *buffer, int len)
|
||||
ESP_LOG_LEVEL(sev, TAG, "esp_transport_read returned:%d and errno:%d ", rlen, errno);
|
||||
}
|
||||
if (rlen < 0 && ridx == 0 && !esp_http_client_is_complete_data_received(client)) {
|
||||
http_dispatch_event(client, HTTP_EVENT_ERROR, esp_transport_get_error_handle(client->transport), 0);
|
||||
return ESP_FAIL;
|
||||
} else {
|
||||
return ridx;
|
||||
@ -1028,6 +1029,7 @@ esp_err_t esp_http_client_perform(esp_http_client_handle_t client)
|
||||
if (client->is_async && err == ESP_ERR_HTTP_CONNECTING) {
|
||||
return ESP_ERR_HTTP_EAGAIN;
|
||||
}
|
||||
http_dispatch_event(client, HTTP_EVENT_ERROR, esp_transport_get_error_handle(client->transport), 0);
|
||||
return err;
|
||||
}
|
||||
/* falls through */
|
||||
@ -1036,6 +1038,7 @@ esp_err_t esp_http_client_perform(esp_http_client_handle_t client)
|
||||
if (client->is_async && errno == EAGAIN) {
|
||||
return ESP_ERR_HTTP_EAGAIN;
|
||||
}
|
||||
http_dispatch_event(client, HTTP_EVENT_ERROR, esp_transport_get_error_handle(client->transport), 0);
|
||||
return err;
|
||||
}
|
||||
/* falls through */
|
||||
@ -1044,6 +1047,7 @@ esp_err_t esp_http_client_perform(esp_http_client_handle_t client)
|
||||
if (client->is_async && errno == EAGAIN) {
|
||||
return ESP_ERR_HTTP_EAGAIN;
|
||||
}
|
||||
http_dispatch_event(client, HTTP_EVENT_ERROR, esp_transport_get_error_handle(client->transport), 0);
|
||||
return err;
|
||||
}
|
||||
/* falls through */
|
||||
@ -1055,14 +1059,17 @@ esp_err_t esp_http_client_perform(esp_http_client_handle_t client)
|
||||
if (esp_tls_get_and_clear_last_error(esp_transport_get_error_handle(client->transport), NULL, NULL) == ESP_ERR_ESP_TLS_TCP_CLOSED_FIN) {
|
||||
ESP_LOGW(TAG, "Close connection due to FIN received");
|
||||
esp_http_client_close(client);
|
||||
http_dispatch_event(client, HTTP_EVENT_ERROR, esp_transport_get_error_handle(client->transport), 0);
|
||||
return ESP_ERR_HTTP_CONNECTION_CLOSED;
|
||||
}
|
||||
http_dispatch_event(client, HTTP_EVENT_ERROR, esp_transport_get_error_handle(client->transport), 0);
|
||||
return ESP_ERR_HTTP_FETCH_HEADER;
|
||||
}
|
||||
/* falls through */
|
||||
case HTTP_STATE_RES_COMPLETE_HEADER:
|
||||
if ((err = esp_http_check_response(client)) != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Error response");
|
||||
http_dispatch_event(client, HTTP_EVENT_ERROR, esp_transport_get_error_handle(client->transport), 0);
|
||||
return err;
|
||||
}
|
||||
while (client->response->is_chunked && !client->is_chunk_complete) {
|
||||
@ -1312,9 +1319,11 @@ esp_err_t esp_http_client_open(esp_http_client_handle_t client, int write_len)
|
||||
client->post_len = write_len;
|
||||
esp_err_t err;
|
||||
if ((err = esp_http_client_connect(client)) != ESP_OK) {
|
||||
http_dispatch_event(client, HTTP_EVENT_ERROR, esp_transport_get_error_handle(client->transport), 0);
|
||||
return err;
|
||||
}
|
||||
if ((err = esp_http_client_request_send(client, write_len)) != ESP_OK) {
|
||||
http_dispatch_event(client, HTTP_EVENT_ERROR, esp_transport_get_error_handle(client->transport), 0);
|
||||
return err;
|
||||
}
|
||||
return ESP_OK;
|
||||
|
Loading…
Reference in New Issue
Block a user