Reconnect on failure
This commit is contained in:
parent
b201649b4b
commit
bb555457c6
@ -117,6 +117,10 @@ export default class AnimeNotifier {
|
|||||||
document.getElementById("status-message-text")
|
document.getElementById("status-message-text")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
this.app.onError = (error: Error) => {
|
||||||
|
this.statusMessage.showError(error, 3000)
|
||||||
|
}
|
||||||
|
|
||||||
// Push manager
|
// Push manager
|
||||||
this.pushManager = new PushManager()
|
this.pushManager = new PushManager()
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import Diff from "./Diff"
|
import Diff from "./Diff"
|
||||||
|
import { delay } from "./Utils"
|
||||||
|
|
||||||
class LoadOptions {
|
class LoadOptions {
|
||||||
addToHistory?: boolean
|
addToHistory?: boolean
|
||||||
@ -13,12 +14,14 @@ export default class Application {
|
|||||||
currentPath: string
|
currentPath: string
|
||||||
originalPath: string
|
originalPath: string
|
||||||
lastRequest: XMLHttpRequest | null
|
lastRequest: XMLHttpRequest | null
|
||||||
|
onError: (err: Error) => void
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.currentPath = window.location.pathname
|
this.currentPath = window.location.pathname
|
||||||
this.originalPath = window.location.pathname
|
this.originalPath = window.location.pathname
|
||||||
this.activeLinkClass = "active"
|
this.activeLinkClass = "active"
|
||||||
this.fadeOutClass = "fade-out"
|
this.fadeOutClass = "fade-out"
|
||||||
|
this.onError = console.error
|
||||||
}
|
}
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
@ -66,7 +69,20 @@ export default class Application {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Start sending a network request
|
// Start sending a network request
|
||||||
let request = this.get("/_" + url).catch(error => error)
|
let request: Promise<string>
|
||||||
|
|
||||||
|
let retry = () => {
|
||||||
|
return this.get("/_" + url).catch(async error => {
|
||||||
|
// Display connection error
|
||||||
|
this.onError(error)
|
||||||
|
|
||||||
|
// Retry after 3 seconds
|
||||||
|
await delay(3000)
|
||||||
|
return retry()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
request = retry()
|
||||||
|
|
||||||
// Parse options
|
// Parse options
|
||||||
if(!options) {
|
if(!options) {
|
||||||
|
@ -31,9 +31,9 @@ export default class StatusMessage {
|
|||||||
this.container.classList.remove("error-message")
|
this.container.classList.remove("error-message")
|
||||||
}
|
}
|
||||||
|
|
||||||
showError(message: string, duration?: number) {
|
showError(message: string | Error, duration?: number) {
|
||||||
this.clearStyle()
|
this.clearStyle()
|
||||||
this.show(message, duration || 4000)
|
this.show(message.toString(), duration || 4000)
|
||||||
this.container.classList.add("error-message")
|
this.container.classList.add("error-message")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user