JSON5.parse in on_upload_progress handler responses
This commit is contained in:
parent
50a4cadfcf
commit
f422157016
@ -445,8 +445,7 @@ export const connect = async (
|
|||||||
});
|
});
|
||||||
|
|
||||||
// On each received message, queue the updates and events.
|
// On each received message, queue the updates and events.
|
||||||
socket.current.on("event", async (message) => {
|
socket.current.on("event", async (update) => {
|
||||||
const update = message;
|
|
||||||
for (const substate in update.delta) {
|
for (const substate in update.delta) {
|
||||||
dispatch[substate](update.delta[substate]);
|
dispatch[substate](update.delta[substate]);
|
||||||
}
|
}
|
||||||
@ -458,7 +457,7 @@ export const connect = async (
|
|||||||
});
|
});
|
||||||
socket.current.on("reload", async (event) => {
|
socket.current.on("reload", async (event) => {
|
||||||
event_processing = false;
|
event_processing = false;
|
||||||
queueEvents([...initialEvents(), JSON5.parse(event)], socket);
|
queueEvents([...initialEvents(), event], socket);
|
||||||
});
|
});
|
||||||
|
|
||||||
document.addEventListener("visibilitychange", checkVisibility);
|
document.addEventListener("visibilitychange", checkVisibility);
|
||||||
@ -499,7 +498,9 @@ export const uploadFiles = async (
|
|||||||
// Whenever called, responseText will contain the entire response so far.
|
// Whenever called, responseText will contain the entire response so far.
|
||||||
const chunks = progressEvent.event.target.responseText.trim().split("\n");
|
const chunks = progressEvent.event.target.responseText.trim().split("\n");
|
||||||
// So only process _new_ chunks beyond resp_idx.
|
// So only process _new_ chunks beyond resp_idx.
|
||||||
chunks.slice(resp_idx).map((chunk) => {
|
chunks.slice(resp_idx).map((chunk_json) => {
|
||||||
|
try {
|
||||||
|
const chunk = JSON5.parse(chunk_json);
|
||||||
event_callbacks.map((f, ix) => {
|
event_callbacks.map((f, ix) => {
|
||||||
f(chunk)
|
f(chunk)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
@ -511,11 +512,17 @@ export const uploadFiles = async (
|
|||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
if (progressEvent.progress === 1) {
|
if (progressEvent.progress === 1) {
|
||||||
// Chunk may be incomplete, so only report errors when full response is available.
|
// Chunk may be incomplete, so only report errors when full response is available.
|
||||||
console.log("Error parsing chunk", chunk, e);
|
console.log("Error processing chunk", chunk, e);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
} catch (e) {
|
||||||
|
if (progressEvent.progress === 1) {
|
||||||
|
console.log("Error parsing chunk", chunk_json, e);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user