From 44e478de3a8966871eae30d23f834b9bda31e1f0 Mon Sep 17 00:00:00 2001 From: James Barlow <332269+manwithacat@users.noreply.github.com> Date: Fri, 24 Apr 2026 12:56:00 +0100 Subject: [PATCH] docs: clarify afterRequest successful/failed reflect responseHandling rule (#3440) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The htmx:afterRequest docs described `detail.successful` and `detail.failed` purely in terms of "20x status code", but the actual logic uses the matched htmx.config.responseHandling rule's `error` flag. When users customize responseHandling to allow non-2xx responses to swap (e.g. `{"code":"...", "swap": true}` without `error: true`), those responses are also marked `successful` — a behavior that surprised the issue reporter. Updates the descriptions of both detail.successful and detail.failed to accurately reference responseHandling, while preserving the default "20x = successful" framing as a parenthetical default-behavior note. Adds an explicit note about the custom responseHandling case. No code change; this aligns documentation with the existing intentional behavior confirmed by @MichaelWest22 in the issue. Co-Authored-By: Claude Opus 4.7 (1M context) --- www/content/events.md | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/www/content/events.md b/www/content/events.md index ebcc3309d..d188fa8f9 100644 --- a/www/content/events.md +++ b/www/content/events.md @@ -48,10 +48,14 @@ can be paired with [`htmx:beforeRequest`](#htmx:beforeRequest) to wrap behavior * `detail.xhr` - the `XMLHttpRequest` * `detail.target` - the target of the request * `detail.requestConfig` - the configuration of the AJAX request -* `detail.successful` - true if the response has a 20x status code or is marked `detail.isError = false` in the - `htmx:beforeSwap` event, else false -* `detail.failed` - true if the response does not have a 20x status code or is marked `detail.isError = true` in the - `htmx:beforeSwap` event, else false +* `detail.successful` - true if the response is not marked as an error by the matched + [`htmx.config.responseHandling`](@/docs.md#response-handling) rule (by default, a 20x status code) or is marked + `detail.isError = false` in the `htmx:beforeSwap` event, else false. Note that if you customize + `responseHandling` to allow non-2xx codes to swap (e.g. `{"code":"...", "swap": true}` without `error: true`), + those responses will also be marked `successful` here. +* `detail.failed` - true if the response is marked as an error by the matched + [`htmx.config.responseHandling`](@/docs.md#response-handling) rule (by default, a non-20x status code) or is marked + `detail.isError = true` in the `htmx:beforeSwap` event, else false ### Event - `htmx:afterSettle` {#htmx:afterSettle}