forked from Shinonome/dots-hyprland
proper error handling
This commit is contained in:
@@ -111,6 +111,14 @@ ApiStrategy {
|
|||||||
return ({})
|
return ({})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Error response handling
|
||||||
|
if (dataJson.error) {
|
||||||
|
const errorMsg = `**Error ${dataJson.error.code}**: ${dataJson.error.message}`;
|
||||||
|
message.rawContent += errorMsg;
|
||||||
|
message.content += errorMsg;
|
||||||
|
return { finished: true };
|
||||||
|
}
|
||||||
|
|
||||||
// No candidates?
|
// No candidates?
|
||||||
if (!dataJson.candidates) return {};
|
if (!dataJson.candidates) return {};
|
||||||
|
|
||||||
|
|||||||
@@ -58,8 +58,17 @@ ApiStrategy {
|
|||||||
// Real stuff
|
// Real stuff
|
||||||
try {
|
try {
|
||||||
const dataJson = JSON.parse(cleanData);
|
const dataJson = JSON.parse(cleanData);
|
||||||
|
|
||||||
|
// Error response handling
|
||||||
|
if (dataJson.error) {
|
||||||
|
const errorMsg = `**Error**: ${dataJson.error.message || JSON.stringify(dataJson.error)}`;
|
||||||
|
message.rawContent += errorMsg;
|
||||||
|
message.content += errorMsg;
|
||||||
|
return { finished: true };
|
||||||
|
}
|
||||||
|
|
||||||
let newContent = "";
|
let newContent = "";
|
||||||
|
|
||||||
const responseContent = dataJson.choices[0]?.delta?.content || dataJson.message?.content;
|
const responseContent = dataJson.choices[0]?.delta?.content || dataJson.message?.content;
|
||||||
const responseReasoning = dataJson.choices[0]?.delta?.reasoning || dataJson.choices[0]?.delta?.reasoning_content;
|
const responseReasoning = dataJson.choices[0]?.delta?.reasoning || dataJson.choices[0]?.delta?.reasoning_content;
|
||||||
|
|
||||||
|
|||||||
@@ -49,8 +49,17 @@ ApiStrategy {
|
|||||||
// Real stuff
|
// Real stuff
|
||||||
try {
|
try {
|
||||||
const dataJson = JSON.parse(cleanData);
|
const dataJson = JSON.parse(cleanData);
|
||||||
|
|
||||||
|
// Error response handling
|
||||||
|
if (dataJson.error) {
|
||||||
|
const errorMsg = `**Error**: ${dataJson.error.message || JSON.stringify(dataJson.error)}`;
|
||||||
|
message.rawContent += errorMsg;
|
||||||
|
message.content += errorMsg;
|
||||||
|
return { finished: true };
|
||||||
|
}
|
||||||
|
|
||||||
let newContent = "";
|
let newContent = "";
|
||||||
|
|
||||||
const responseContent = dataJson.choices[0]?.delta?.content || dataJson.message?.content;
|
const responseContent = dataJson.choices[0]?.delta?.content || dataJson.message?.content;
|
||||||
const responseReasoning = dataJson.choices[0]?.delta?.reasoning || dataJson.choices[0]?.delta?.reasoning_content;
|
const responseReasoning = dataJson.choices[0]?.delta?.reasoning || dataJson.choices[0]?.delta?.reasoning_content;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user