mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 16:23:36 +00:00
use specific openai errors
This commit is contained in:
1 parent
00d9d4d005
commit
10ea68547c
1 file changed
+3
-24
@@ -410,34 +410,13 @@ export class SessionManager {
|
||||
|
||||
// Convert provider errors to standard OpenAI APIError with appropriate code
|
||||
if (error?.status === 400) {
|
||||
const code = 'bad_request';
|
||||
const apiError = new OpenAI.APIError({
|
||||
status: error.status,
|
||||
code,
|
||||
message: `${error.status} Provider returned error`
|
||||
});
|
||||
apiError.code = code;
|
||||
throw apiError;
|
||||
throw new OpenAI.BadRequestError(400, { code: 'bad_request' }, error.message, new Headers());
|
||||
}
|
||||
if (error?.status === 403) {
|
||||
const code = 'key_limit_exceeded';
|
||||
const apiError = new OpenAI.APIError({
|
||||
status: error.status,
|
||||
code,
|
||||
message: `${error.status} Provider returned error`
|
||||
});
|
||||
apiError.code = code;
|
||||
throw apiError;
|
||||
throw new OpenAI.PermissionDeniedError(403, { code: 'key_limit_exceeded' }, error.message, new Headers());
|
||||
}
|
||||
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;
|
||||
throw new OpenAI.UnprocessableEntityError(422, { code: 'unprocessable_entity' }, error.message, new Headers());
|
||||
}
|
||||
|
||||
// Re-throw service errors to be handled at the UI level
|
||||
|
||||
Reference in new issue
Block a user