use try / catch with 10 seconds wait in case of error

This commit is contained in:
Helmut Merz 2023-02-20 11:20:11 +01:00
parent 6644a8f88c
commit 9bdde0637d

View file

@ -1,5 +1,7 @@
import { createApp } from './lib/petite-vue.es.js'
const apiUrl = 'http://localhost:8125/api/system/poll/service/pclt-0001'
const appdata = {
$delimiters: ['{|', '|}'],
urlParams: new URL(location.href).searchParams,
@ -20,30 +22,21 @@ function save() {
this.newdata = ''
}
const apiUrl = 'http://localhost:8125/api/system/poll/service/pclt-0001'
async function dopoll(obj: typeof appdata) {
async function dopoll(obj: typeof appdata, url: string) {
while (true) {
let res = await fetch('http://localhost:8125/api/system/poll/service/pclt-0001')
//let res = await fetch(apiUrl)
let data = await res.json()
console.log(data)
obj.newdata = data['status']
try {
let res = await fetch(url)
let data = await res.json()
console.log(data)
obj.newdata = data['status']
} catch (error) {
console.log(error)
await new Promise(r => setTimeout(r, 10000))
}
}
}
function poll() {
dopoll(this)
}
function x_poll() {
fetch('http://localhost:8125/api/system/poll/service/pclt-0001')
.then((res) => res.json())
.then((data) => {
console.log(data)
this.newdata = data['status']
this.poll()
})
return null
dopoll(this, apiUrl)
}