Fix #37 Improve 401 resporting

This commit is contained in:
gabrii
2025-09-16 08:53:19 +02:00
parent 3699ca3aa4
commit 1856dd473e
3 changed files with 15 additions and 5 deletions
+10 -1
View File
@@ -20,6 +20,15 @@ def require_auth(func):
if valid_brearer_token():
return func(*args, **kwargs)
else:
return Response("Unauthorized", 401)
error_message = (
"\nAuthentication with Cursor-Azure-GPT-5 service failed.\n\n"
"These value of:\n"
"\tCursor Settings > Models > API Keys > OpenAI API Key\n\n"
"Must match the value of:\n"
"\tSERVICE_API_KEY in your .env file\n\n"
"Ensure the values match exactly, and try again.\n"
"If modifying the .env file, restart the service for the changes to apply."
)
return Response(error_message, 400)
return wrapper
+2 -1
View File
@@ -86,6 +86,7 @@ class AzureAdapter:
"endpoint": re.sub(
r"(//.)(.*?)(.\.)", "\\1***\\3", request_kwargs.get("url")
),
"azure_status_code": resp.status_code,
"azure_response": resp_content,
"request_body": body,
}
@@ -102,5 +103,5 @@ class AzureAdapter:
console.print(error_message)
return Response(
error_message,
status=resp.status_code,
status=resp.status_code if resp.status_code != 401 else 400,
)
+3 -3
View File
@@ -17,9 +17,9 @@ class TestConfig:
class TestModels:
"""Models."""
def test_models_endpoint_returns_200(self, testapp):
"""Ensure /models endpoint returns HTTP 200."""
testapp.get("/models", status=401)
def test_models_endpoint_returns_400(self, testapp):
"""Ensure /models endpoint returns HTTP 400."""
testapp.get("/models", status=400)
def test_health_endpoint_returns_200(self, testapp):
"""Ensure /health endpoint returns HTTP 200."""