Return 502 with error description when connection to remote CC API fails
If chat-completions/generate returns an error, throw the error message Reformat display of exceptions during SD prompt text generation
This commit is contained in:
parent
0383ea52e9
commit
8de551fc94
|
@ -2432,8 +2432,12 @@ async function generatePicture(initiator, args, trigger, message, callback) {
|
|||
imagePath = await sendGenerationRequest(generationType, prompt, negativePromptPrefix, characterName, callback, initiator, abortController.signal);
|
||||
} catch (err) {
|
||||
console.trace(err);
|
||||
toastr.error('SD prompt text generation failed. Reason: ' + err, 'Image Generation');
|
||||
throw new Error('SD prompt text generation failed. Reason: ' + err);
|
||||
// errors here are most likely due to text generation failure
|
||||
// sendGenerationRequest mostly deals with its own errors
|
||||
const reason = err.error?.message || err.message || 'Unknown error';
|
||||
const errorText = 'SD prompt text generation failed. ' + reason;
|
||||
toastr.error(errorText, 'Image Generation');
|
||||
throw new Error(errorText);
|
||||
}
|
||||
finally {
|
||||
$(stopButton).hide();
|
||||
|
|
|
@ -2057,8 +2057,9 @@ async function sendOpenAIRequest(type, messages, signal) {
|
|||
checkModerationError(data);
|
||||
|
||||
if (data.error) {
|
||||
toastr.error(data.error.message || response.statusText, t`API returned an error`);
|
||||
throw new Error(data);
|
||||
const message = data.error.message || response.statusText || t`Unknown error`;
|
||||
toastr.error(message, t`API returned an error`);
|
||||
throw new Error(message);
|
||||
}
|
||||
|
||||
if (type !== 'quiet') {
|
||||
|
|
|
@ -1051,8 +1051,12 @@ router.post('/generate', jsonParser, function (request, response) {
|
|||
}
|
||||
} catch (error) {
|
||||
console.log('Generation failed', error);
|
||||
const message = error.code === 'ECONNREFUSED'
|
||||
? `Connection refused: ${error.message}`
|
||||
: error.message || 'Unknown error occurred';
|
||||
|
||||
if (!response.headersSent) {
|
||||
response.send({ error: true });
|
||||
response.status(502).send({ error: { message, ...error } });
|
||||
} else {
|
||||
response.end();
|
||||
}
|
||||
|
@ -1068,7 +1072,7 @@ router.post('/generate', jsonParser, function (request, response) {
|
|||
|
||||
const message = errorResponse.statusText || 'Unknown error occurred';
|
||||
const quota_error = errorResponse.status === 429 && errorData?.error?.type === 'insufficient_quota';
|
||||
console.log(message, responseText);
|
||||
console.log('Chat completion request error: ', message, responseText);
|
||||
|
||||
if (!response.headersSent) {
|
||||
response.send({ error: { message }, quota_error: quota_error });
|
||||
|
|
Loading…
Reference in New Issue