[Fix] Improve OpenAI authentication handling and error response
This commit is contained in:
@@ -1813,6 +1813,8 @@ class Controller:
|
||||
try:
|
||||
data = str(data)
|
||||
if data.startswith("sk-") and len(data) >= 164:
|
||||
result = model.authenticationTranslatorOpenAIAuthKey(auth_key=data)
|
||||
if result is True:
|
||||
key = data
|
||||
auth_keys = config.AUTH_KEYS
|
||||
auth_keys[translator_name] = key
|
||||
@@ -1827,6 +1829,14 @@ class Controller:
|
||||
model.updateTranslatorOpenAIClient()
|
||||
self.updateTranslationEngineAndEngineList()
|
||||
response = {"status":200, "result":config.AUTH_KEYS[translator_name]}
|
||||
else:
|
||||
response = {
|
||||
"status":400,
|
||||
"result":{
|
||||
"message":"Authentication failure of OpenAI auth key",
|
||||
"data": config.AUTH_KEYS[translator_name]
|
||||
}
|
||||
}
|
||||
else:
|
||||
response = {
|
||||
"status":400,
|
||||
|
||||
Reference in New Issue
Block a user