mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-06 08:37:22 +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
|
// Convert provider errors to standard OpenAI APIError with appropriate code
|
||||||
if (error?.status === 400) {
|
if (error?.status === 400) {
|
||||||
const code = 'bad_request';
|
throw new OpenAI.BadRequestError(400, { code: 'bad_request' }, error.message, new Headers());
|
||||||
const apiError = new OpenAI.APIError({
|
|
||||||
status: error.status,
|
|
||||||
code,
|
|
||||||
message: `${error.status} Provider returned error`
|
|
||||||
});
|
|
||||||
apiError.code = code;
|
|
||||||
throw apiError;
|
|
||||||
}
|
}
|
||||||
if (error?.status === 403) {
|
if (error?.status === 403) {
|
||||||
const code = 'key_limit_exceeded';
|
throw new OpenAI.PermissionDeniedError(403, { code: 'key_limit_exceeded' }, error.message, new Headers());
|
||||||
const apiError = new OpenAI.APIError({
|
|
||||||
status: error.status,
|
|
||||||
code,
|
|
||||||
message: `${error.status} Provider returned error`
|
|
||||||
});
|
|
||||||
apiError.code = code;
|
|
||||||
throw apiError;
|
|
||||||
}
|
}
|
||||||
if (error?.status === 422) {
|
if (error?.status === 422) {
|
||||||
const code = 'unprocessable_entity'
|
throw new OpenAI.UnprocessableEntityError(422, { code: 'unprocessable_entity' }, error.message, new Headers());
|
||||||
const apiError = new OpenAI.APIError({
|
|
||||||
status: error.status,
|
|
||||||
code,
|
|
||||||
message: `${error.status} Provider returned error`
|
|
||||||
});
|
|
||||||
apiError.code = code;
|
|
||||||
throw apiError;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Re-throw service errors to be handled at the UI level
|
// Re-throw service errors to be handled at the UI level
|
||||||
|
|||||||
Reference in new issue
Block a user