mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-02-23 07:27:41 +01:00
#844 Properly handle KoboldAI errors
This commit is contained in:
parent
5645432e9d
commit
7596d78322
@ -2789,7 +2789,8 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject,
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(response.status);
|
||||
const error = await response.json();
|
||||
throw error;
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
@ -2959,6 +2960,10 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject,
|
||||
};
|
||||
|
||||
function onError(exception) {
|
||||
if (typeof exception?.error?.message === 'string') {
|
||||
toastr.error(exception.error.message, 'Error', { timeOut: 10000, extendedTimeOut: 20000 });
|
||||
}
|
||||
|
||||
reject(exception);
|
||||
$("#send_textarea").removeAttr('disabled');
|
||||
is_send_press = false;
|
||||
|
12
server.js
12
server.js
@ -506,8 +506,16 @@ app.post("/generate", jsonParser, async function (request, response_generate = r
|
||||
return response.body.pipe(response_generate);
|
||||
} else {
|
||||
if (!response.ok) {
|
||||
console.log(`Kobold returned error: ${response.status} ${response.statusText} ${await response.text()}`);
|
||||
return response.status(response.status).send({ error: true });
|
||||
const errorText = await response.text();
|
||||
console.log(`Kobold returned error: ${response.status} ${response.statusText} ${errorText}`);
|
||||
|
||||
try {
|
||||
const errorJson = JSON.parse(errorText);
|
||||
const message = errorJson?.detail?.msg || errorText;
|
||||
return response_generate.status(400).send({ error: { message } });
|
||||
} catch {
|
||||
return response_generate.status(400).send({ error: { message: errorText } });
|
||||
}
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
|
Loading…
x
Reference in New Issue
Block a user