🐛 Bug: Fix the issue where an error is returned directly when Authorization is empty.
Browse files
main.py
CHANGED
@@ -408,7 +408,14 @@ class StatsMiddleware(BaseHTTPMiddleware):
|
|
408 |
if request.headers.get("x-api-key"):
|
409 |
token = request.headers.get("x-api-key")
|
410 |
elif request.headers.get("Authorization"):
|
411 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
412 |
else:
|
413 |
token = None
|
414 |
if token:
|
@@ -1016,11 +1023,11 @@ class ModelRequestHandler:
|
|
1016 |
|
1017 |
cooling_time = safe_get(provider, "preferences", "api_key_cooldown_period", default=0)
|
1018 |
api_key_count = provider_api_circular_list[channel_id].get_items_count()
|
|
|
1019 |
if cooling_time > 0 and api_key_count > 1:
|
1020 |
-
current_api = await provider_api_circular_list[channel_id].after_next_current()
|
1021 |
await provider_api_circular_list[channel_id].set_cooling(current_api, cooling_time=cooling_time)
|
1022 |
|
1023 |
-
logger.error(f"Error {status_code} with provider {channel_id}: {error_message}")
|
1024 |
if is_debug:
|
1025 |
import traceback
|
1026 |
traceback.print_exc()
|
|
|
408 |
if request.headers.get("x-api-key"):
|
409 |
token = request.headers.get("x-api-key")
|
410 |
elif request.headers.get("Authorization"):
|
411 |
+
api_split_list = request.headers.get("Authorization").split(" ")
|
412 |
+
if len(api_split_list) > 1:
|
413 |
+
token = api_split_list[1]
|
414 |
+
else:
|
415 |
+
return JSONResponse(
|
416 |
+
status_code=403,
|
417 |
+
content={"error": "Invalid or missing API Key"}
|
418 |
+
)
|
419 |
else:
|
420 |
token = None
|
421 |
if token:
|
|
|
1023 |
|
1024 |
cooling_time = safe_get(provider, "preferences", "api_key_cooldown_period", default=0)
|
1025 |
api_key_count = provider_api_circular_list[channel_id].get_items_count()
|
1026 |
+
current_api = await provider_api_circular_list[channel_id].after_next_current()
|
1027 |
if cooling_time > 0 and api_key_count > 1:
|
|
|
1028 |
await provider_api_circular_list[channel_id].set_cooling(current_api, cooling_time=cooling_time)
|
1029 |
|
1030 |
+
logger.error(f"Error {status_code} with provider {channel_id} API key: {current_api}: {error_message}")
|
1031 |
if is_debug:
|
1032 |
import traceback
|
1033 |
traceback.print_exc()
|