JSON parsing lines error handling improved in APIs. See #550
This commit is contained in:
parent
29891df80e
commit
b540e0ba73
4 changed files with 36 additions and 12 deletions
|
|
@ -106,9 +106,15 @@ self.onmessage = async function(event) {
|
|||
.filter((line) => line !== "" ) // Remove empty lines
|
||||
// .map((line) => JSON.parse(line)); // Parse the JSON string
|
||||
.map((line) => {
|
||||
taLog.log("line: " + JSON.stringify(line));
|
||||
return JSON.parse(line);
|
||||
});
|
||||
try {
|
||||
taLog.log("line: " + JSON.stringify(line));
|
||||
return JSON.parse(line);
|
||||
} catch (e) {
|
||||
taLog.warn("JSON parse warning, skipped line: " + line + " - " + e.message);
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.filter((parsed) => parsed !== null);
|
||||
}catch(e){
|
||||
taLog.error("Error parsing lines: " + e);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -112,9 +112,15 @@ self.onmessage = async function(event) {
|
|||
.filter((line) => line !== "" && line !== "[DONE]") // Remove empty lines and "[DONE]"
|
||||
// .map((line) => JSON.parse(line)); // Parse the JSON string
|
||||
.map((line) => {
|
||||
taLog.log("line: " + JSON.stringify(line));
|
||||
return JSON.parse(line);
|
||||
});
|
||||
try {
|
||||
taLog.log("line: " + JSON.stringify(line));
|
||||
return JSON.parse(line);
|
||||
} catch (e) {
|
||||
taLog.warn("JSON parse warning, skipped line: " + line + " - " + e.message);
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.filter((parsed) => parsed !== null);
|
||||
}catch(e){
|
||||
taLog.error("Error parsing lines: " + e);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -106,9 +106,15 @@ self.onmessage = async function(event) {
|
|||
.filter((line) => line !== "" && line !== "[DONE]") // Remove empty lines and "[DONE]"
|
||||
// .map((line) => JSON.parse(line)); // Parse the JSON string
|
||||
.map((line) => {
|
||||
taLog.log("line: " + JSON.stringify(line));
|
||||
return JSON.parse(line);
|
||||
});
|
||||
try {
|
||||
taLog.log("line: " + JSON.stringify(line));
|
||||
return JSON.parse(line);
|
||||
} catch (e) {
|
||||
taLog.warn("JSON parse warning, skipped line: " + line + " - " + e.message);
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.filter((parsed) => parsed !== null);
|
||||
}catch(e){
|
||||
taLog.error("Error parsing lines: " + e);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -111,9 +111,15 @@ self.onmessage = async function(event) {
|
|||
.filter((line) => line !== "" && line !== "[DONE]") // Remove empty lines and "[DONE]"
|
||||
// .map((line) => JSON.parse(line)); // Parse the JSON string
|
||||
.map((line) => {
|
||||
taLog.log("line: " + JSON.stringify(line));
|
||||
return JSON.parse(line);
|
||||
});
|
||||
try {
|
||||
taLog.log("line: " + JSON.stringify(line));
|
||||
return JSON.parse(line);
|
||||
} catch (e) {
|
||||
taLog.warn("JSON parse warning, skipped line: " + line + " - " + e.message);
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.filter((parsed) => parsed !== null);
|
||||
}catch(e){
|
||||
taLog.error("Error parsing lines: " + e);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue