mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 16:23:36 +00:00
handle 400s too
This commit is contained in:
1 parent
185cdc51fb
commit
52198a0a3c
2 files changed
+26
-6
No files matched your search
@@ -114,6 +114,15 @@ export function Quilly({ error, onDismiss, onNewChat, onOpenModelSelector, onReq
|
||||
},
|
||||
};
|
||||
|
||||
case 'bad_request':
|
||||
return {
|
||||
message: 'Invalid request parameters. Try a different model.',
|
||||
action: {
|
||||
label: 'Choose model',
|
||||
onClick: onOpenModelSelector,
|
||||
},
|
||||
};
|
||||
|
||||
case 'unprocessable_entity':
|
||||
return {
|
||||
message: 'Request rejected by AI provider. Try a different model.',
|
||||
|
||||
@@ -408,14 +408,25 @@ export class SessionManager {
|
||||
return; // User cancelled
|
||||
}
|
||||
|
||||
// Convert UnprocessableEntityError to standard OpenAI APIError with code
|
||||
if (error?.constructor?.name === 'UnprocessableEntityError') {
|
||||
// Convert provider errors to standard OpenAI APIError with appropriate code
|
||||
if (error?.status === 400) {
|
||||
const code = 'bad_request';
|
||||
const apiError = new OpenAI.APIError({
|
||||
status: 422,
|
||||
code: 'unprocessable_entity',
|
||||
message: '422 Provider returned error'
|
||||
status: error.status,
|
||||
code,
|
||||
message: `${error.status} Provider returned error`
|
||||
});
|
||||
apiError.code = 'unprocessable_entity';
|
||||
apiError.code = code;
|
||||
throw apiError;
|
||||
}
|
||||
if (error?.status === 422) {
|
||||
const code = 'unprocessable_entity'
|
||||
const apiError = new OpenAI.APIError({
|
||||
status: error.status,
|
||||
code,
|
||||
message: `${error.status} Provider returned error`
|
||||
});
|
||||
apiError.code = code;
|
||||
throw apiError;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user