Skip to content

Commit

Permalink
feat(connect): Display "connection lost" toast only once. Fixes (#705) (
Browse files Browse the repository at this point in the history
#936)

Signed-off-by: Grzegorz Grzybek <[email protected]>
  • Loading branch information
grgrzybek authored May 10, 2024
1 parent 1506cd5 commit a25eeba
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions packages/hawtio/src/plugins/shared/jolokia-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ class JolokiaService implements IJolokiaService {
private ajaxError(resolve?: AjaxErrorResolver): JQueryAjaxError {
const errorThreshold = 2
let errorCount = 0
let errorToastDisplayed = false
return (xhr: JQueryXHR) => {
switch (xhr.status) {
case 401:
Expand Down Expand Up @@ -340,14 +341,21 @@ class JolokiaService implements IJolokiaService {
errorCount++
const updateRate = this.loadUpdateRate()
const validityPeriod = updateRate * (errorThreshold + 1)
setTimeout(() => errorCount--, validityPeriod)
if (errorCount > errorThreshold) {
setTimeout(() => {
errorCount--
if (errorCount == 0) {
errorToastDisplayed = false
}
return errorCount
}, validityPeriod)
if (errorCount > errorThreshold && !errorToastDisplayed) {
eventService.notify({
type: 'danger',
message: 'Connection lost. Retrying...',
message: 'Connection lost. Will attempt reconnection...',
// -100ms is to not overlap between update and notification
duration: updateRate - 100,
})
errorToastDisplayed = true
}
}
}
Expand Down

0 comments on commit a25eeba

Please sign in to comment.