Improve Horde request error detection

This commit is contained in:
Cohee 2023-08-27 13:31:14 +03:00
parent 56f13b6966
commit 109ea4008b
2 changed files with 18 additions and 5 deletions

View File

@ -117,12 +117,18 @@ async function generateHorde(prompt, params, signal) {
});
if (!response.ok) {
const error = await response.json();
callPopup(error.message, 'text');
throw new Error('Horde generation failed: ' + error.message);
toastr.error(response.statusText, 'Horde generation failed');
throw new Error(`Horde generation failed: ${response.statusText}`);
}
const responseJson = await response.json();
if (responseJson.error) {
const reason = responseJson.error?.message || 'Unknown error';
toastr.error(reason, 'Horde generation failed');
throw new Error(`Horde generation failed: ${reason}`);
}
const task_id = responseJson.id;
let queue_position_first = null;
console.log(`Horde task id = ${task_id}`);

View File

@ -4202,8 +4202,15 @@ app.post('/generate_horde', jsonParser, async (request, response) => {
const data = await postAsync(url, args);
return response.send(data);
} catch (error) {
console.error(error);
return response.sendStatus(500);
console.log('Horde returned an error:', error.statusText);
if (typeof error.text === 'function') {
const message = await error.text();
console.log(message);
return response.send({ error: { message } });
} else {
return response.send({ error: true });
}
}
});