UrlPlayer: process HTTP responses to invalid requests

This commit is contained in:
He4eT 2023-05-24 21:52:36 +03:00 committed by Alexey
commit e7c1384436

View file

@ -26,10 +26,16 @@ const prepareVM = ({ url, setStatus, setParts }) => {
fetch(wasmBinaryName) fetch(wasmBinaryName)
.then((response) => response.arrayBuffer()) .then((response) => response.arrayBuffer())
const checkResponse = (response) => {
if (response.ok) return response
throw new Error(response.statusText)
}
return Promise.resolve(url) return Promise.resolve(url)
.then(st('loading', 'Downloading file')) .then(st('loading', 'Downloading file'))
.then(cleanUrl) .then(cleanUrl)
.then(fetch) .then(fetch)
.then(checkResponse)
.then(st('loading', 'Processing file')) .then(st('loading', 'Processing file'))
.then((response) => response.arrayBuffer()) .then((response) => response.arrayBuffer())
.then((arrayBuffer) => new Uint8Array(arrayBuffer)) .then((arrayBuffer) => new Uint8Array(arrayBuffer))