Skip to content

Commit 44e478d

Browse files
manwithacatclaude
andcommitted
docs: clarify afterRequest successful/failed reflect responseHandling rule (#3440)
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) <noreply@anthropic.com>
1 parent dbf77dd commit 44e478d

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

www/content/events.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,14 @@ can be paired with [`htmx:beforeRequest`](#htmx:beforeRequest) to wrap behavior
4848
* `detail.xhr` - the `XMLHttpRequest`
4949
* `detail.target` - the target of the request
5050
* `detail.requestConfig` - the configuration of the AJAX request
51-
* `detail.successful` - true if the response has a 20x status code or is marked `detail.isError = false` in the
52-
`htmx:beforeSwap` event, else false
53-
* `detail.failed` - true if the response does not have a 20x status code or is marked `detail.isError = true` in the
54-
`htmx:beforeSwap` event, else false
51+
* `detail.successful` - true if the response is not marked as an error by the matched
52+
[`htmx.config.responseHandling`](@/docs.md#response-handling) rule (by default, a 20x status code) or is marked
53+
`detail.isError = false` in the `htmx:beforeSwap` event, else false. Note that if you customize
54+
`responseHandling` to allow non-2xx codes to swap (e.g. `{"code":"...", "swap": true}` without `error: true`),
55+
those responses will also be marked `successful` here.
56+
* `detail.failed` - true if the response is marked as an error by the matched
57+
[`htmx.config.responseHandling`](@/docs.md#response-handling) rule (by default, a non-20x status code) or is marked
58+
`detail.isError = true` in the `htmx:beforeSwap` event, else false
5559

5660
### Event - `htmx:afterSettle` {#htmx:afterSettle}
5761

0 commit comments

Comments
 (0)