Skip to content

Retry on responseError? #1746

Answered by Telroshan
tobymurray asked this question in Q&A
Aug 30, 2023 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

hey, the htmx:responseError event contains a reference to the original event that triggered the request, in its requestConfig property.
See this JSFiddle ; open the dev console, and notice how request are retried every 1 s, both for the button (click event) and the form (submit event), handled in a generic manner
The JS code for reference:

<script type="text/javascript">
  document.body.addEventListener("htmx:responseError", function(event) {
    // Process the error

    // Retrieve which event fired the request, trigger it again
    const eventType = event.detail.requestConfig.triggeringEvent.type
    setTimeout(function() {
      htmx.trigger(event.detail.elt, eventType)
    }, 1000) /…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@tobymurray
Comment options

Answer selected by tobymurray
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants