modify browser history on network error (so refresh would retry loading that page)

This commit is contained in:
iacore
2024-02-20 00:01:01 +00:00
parent 525581f9a4
commit c5553fe953
2 changed files with 9 additions and 4 deletions
+2 -2
View File
@@ -213,10 +213,10 @@ func main() {
if config.GlobalServerConfig.InDevelopment {
go func() {
cmd := exec.Command("sass", "--watch", "views/css")
cmd.Stdout = os.Stderr // heh. (sass quirk)
cmd.Stdout = os.Stderr // Sass quirk
cmd.Stderr = os.Stderr
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true, Pdeathsig: syscall.SIGHUP}
runtime.LockOSThread() // O.O https://github.com/golang/go/issues/27505
runtime.LockOSThread() // Go quirk https://github.com/golang/go/issues/27505
err := cmd.Run()
if err != nil {
log.Println(fmt.Errorf("when running sass: %w", err))
+7 -2
View File
@@ -1,7 +1,12 @@
// make 4xx 5xx responses swap in as well
// on network error when clicking on a link, navigate to the page anyway
addEventListener('htmx:sendError', function (event) {
document.write("A network error prevented an HTTP request from occurring, which is likely because the server is down. Check your Developer Console's Network tab to know what exactly is wrong.")
if (event.target.tagName == "A") {
// if the server is down, this will show the browser's default "Unable to connect" page, which is familiar to the user
document.location = event.detail.pathInfo.requestPath
}
});
// make 4xx 5xx responses swap in as well
addEventListener('htmx:beforeOnLoad', function (event) {
// console.log("%o", event)
event.detail.shouldSwap = true;