From 07b045375d7262cbdf0c3e230e605c48e613bb5d Mon Sep 17 00:00:00 2001 From: Clyde Stubbs <2366188+clydebarrow@users.noreply.github.com> Date: Wed, 30 Oct 2024 12:11:01 +1100 Subject: [PATCH] [http_request] Document on_error trigger (#4401) --- components/http_request.rst | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/components/http_request.rst b/components/http_request.rst index 1acaa7658..4b599bbc7 100644 --- a/components/http_request.rst +++ b/components/http_request.rst @@ -105,6 +105,7 @@ This :ref:`action ` sends a GET request. - **max_response_buffer_size** (*Optional*, integer): The maximum buffer size to be used to store the response. Defaults to ``1 kB``. - **on_response** (*Optional*, :ref:`Automation `): An automation to perform after the request is received. +- **on_error** (*Optional*, :ref:`Automation `): An automation to perform if the request cannot be completed. .. _http_request-post_action: @@ -186,6 +187,20 @@ The following variables are available for use in :ref:`lambdas `: - response->duration_ms - lambda: |- ESP_LOGD(TAG, "Response status: %d, Duration: %u ms", response->status_code, response->duration_ms); + on_error: + then: + - logger.log: "Request failed!" + + +.. _http_request-on_error: + +``on_error`` Trigger +----------------------- + +This automation will be triggered when the HTTP request fails to complete. This may be e.g. when the network is not available, +or the server is not reachable. This will *not* be triggered if the request +completes, even if the response code is not 200. No information on the type of error is available and no variables +are available for use in :ref:`lambdas `. See example usage above. .. _http_request-examples: