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