Skip to content

Commit

Permalink
audio: handle HTTP status special value -1
Browse files Browse the repository at this point in the history
In commit af99de4 ("audio: reduce HTTP Stream timeout to 2s") we
changed the HTTP Stream timeout to 2s so we can indicate early when
we're not able to connect to WIS.

Unfortunately ESP HTTP Client only has a single timeout value, and we
now also abort the HTTP connection to WIS if inference takes longer than
2s. We want to keep the timeout reasonably low, as having to wait for a
STT response for too long isn't great for UX, but -1 is not a valid HTTP
status code and it will confuse users hitting it.

Handle the special HTTP status value -1 and inform the user that a
timeout occurred while talking to WIS.
  • Loading branch information
stintel committed Dec 12, 2023
1 parent f41288e commit a82ef37
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion main/audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,11 @@ static esp_err_t hdl_ev_hs_to_api(http_stream_event_msg_t *msg)
// Check status code
int http_status = esp_http_client_get_status_code(http);
if (http_status != 200) {
if (http_status == 401) {
// when ESP HTTP Client terminates connection due to timeout we get -1
if (http_status == -1) {
ESP_LOGE(TAG, "WIS response took longer than %dms, connection aborted", HTTP_STREAM_TIMEOUT_MS);
ui_pr_err("WIS timeout", "Check server performance");
} else if (http_status == 401) {
ESP_LOGE(TAG, "WIS returned Unauthorized Access (HTTP 401)");
ui_pr_err("WIS auth failed", "Check server & settings");
} else if (http_status == 406) {
Expand Down

0 comments on commit a82ef37

Please sign in to comment.