e.message wont start with 'JSON.parse' on mobile.

Removed message check but made the try/catch more narrow to not hide other errors.
This commit is contained in:
Marc-Andre Ferland 2022-10-11 13:48:18 -04:00
parent 3abd570678
commit d1fa13d67a

View File

@ -497,42 +497,41 @@ async function doMakeImage(task) {
let timeTaken = (prevTime === -1 ? -1 : t - prevTime) let timeTaken = (prevTime === -1 ? -1 : t - prevTime)
let jsonStr = textDecoder.decode(value) let jsonStr = textDecoder.decode(value)
let stepUpdate = undefined
try { try {
let stepUpdate = JSON.parse(jsonStr) stepUpdate = JSON.parse(jsonStr)
if (stepUpdate.step === undefined) {
finalJSON += jsonStr
} else {
let batchSize = stepUpdate.total_steps
let overallStepCount = stepUpdate.step + task.batchesDone * batchSize
let totalSteps = batchCount * batchSize
let percent = 100 * (overallStepCount / totalSteps)
percent = (percent > 100 ? 100 : percent)
percent = percent.toFixed(0)
let stepsRemaining = totalSteps - overallStepCount
stepsRemaining = (stepsRemaining < 0 ? 0 : stepsRemaining)
let timeRemaining = (timeTaken === -1 ? '' : stepsRemaining * timeTaken) // ms
outputMsg.innerHTML = `Batch ${task.batchesDone+1} of ${batchCount}`
outputMsg.innerHTML += `. Generating image(s): ${percent}%`
timeRemaining = (timeTaken !== -1 ? millisecondsToStr(timeRemaining) : '')
outputMsg.innerHTML += `. Time remaining (approx): ${timeRemaining}`
outputMsg.style.display = 'block'
if (stepUpdate.output !== undefined) {
showImages(reqBody, stepUpdate, outputContainer, true)
}
}
} catch (e) { } catch (e) {
if (e instanceof SyntaxError && e.message.startsWith('JSON.parse')) { if (e instanceof SyntaxError) {
finalJSON += jsonStr finalJSON += jsonStr
} else { } else {
throw e throw e
} }
} }
if (!stepUpdate || stepUpdate.step === undefined) {
finalJSON += jsonStr
} else {
let batchSize = stepUpdate.total_steps
let overallStepCount = stepUpdate.step + task.batchesDone * batchSize
let totalSteps = batchCount * batchSize
let percent = 100 * (overallStepCount / totalSteps)
percent = (percent > 100 ? 100 : percent)
percent = percent.toFixed(0)
let stepsRemaining = totalSteps - overallStepCount
stepsRemaining = (stepsRemaining < 0 ? 0 : stepsRemaining)
let timeRemaining = (timeTaken === -1 ? '' : stepsRemaining * timeTaken) // ms
outputMsg.innerHTML = `Batch ${task.batchesDone+1} of ${batchCount}`
outputMsg.innerHTML += `. Generating image(s): ${percent}%`
timeRemaining = (timeTaken !== -1 ? millisecondsToStr(timeRemaining) : '')
outputMsg.innerHTML += `. Time remaining (approx): ${timeRemaining}`
outputMsg.style.display = 'block'
if (stepUpdate.output !== undefined) {
showImages(reqBody, stepUpdate, outputContainer, true)
}
}
prevTime = t prevTime = t
} catch (e) { } catch (e) {