Skip to content

docs: clarify afterRequest successful/failed reflect responseHandling rule (#3440)#3770

Open
manwithacat wants to merge 1 commit intobigskysoftware:masterfrom
manwithacat:fix/docs-afterRequest-successful-responseHandling
Open

docs: clarify afterRequest successful/failed reflect responseHandling rule (#3440)#3770
manwithacat wants to merge 1 commit intobigskysoftware:masterfrom
manwithacat:fix/docs-afterRequest-successful-responseHandling

Conversation

@manwithacat
Copy link
Copy Markdown
Contributor

Fixes #3440.

The htmx:afterRequest event docs described detail.successful and detail.failed purely as "true if 20x status code", but the actual code (at src/htmx.js:4849, 4893–4894) derives them from the matched htmx.config.responseHandling rule's error flag:

const shouldSwap = responseHandling.swap
let isError = !!responseHandling.error
// ... beforeSwap can override isError ...
responseInfo.failed = isError
responseInfo.successful = !isError

When users customize responseHandling to allow non-2xx responses to swap — for example with {"code":"...", "swap": true} and no error: true — those responses are also marked successful in htmx:afterRequest. The issue reporter was surprised by this. As @MichaelWest22 confirmed in the issue, the behavior is intentional ("If you override the default of what is defined as successful to swap then you would expect this to flow though"); the docs were just incomplete.

This PR rewords the descriptions of both detail.successful and detail.failed to:

  1. Reference htmx.config.responseHandling as the source of truth.
  2. Keep the "20x = successful" framing as a parenthetical "by default" note so existing readers' mental model is preserved.
  3. Add an explicit note about the custom responseHandling case so future users with the same setup don't hit the same surprise.

Docs-only — targeting master per CONTRIBUTING.md. No code change.

… rule (bigskysoftware#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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

event.detail.successful always true with hx-on:after-request when allowing all responses status to swap

1 participant