Skip to content

Commit 9af3f44

Browse files
authored
refactor(constants): complete error_constants adoption (#3550)
Closes #3550
1 parent 11c3be3 commit 9af3f44

File tree

5 files changed

+5
-13
lines changed

5 files changed

+5
-13
lines changed

autobot-backend/api/api_endpoint_migrations_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17656,7 +17656,7 @@ def test_batch_99_schedule_template_workflow_preserves_400_and_404(self):
1765617656
self.assertIn("Invalid JSON in variables parameter", source)
1765717657
# Should preserve 404 HTTPException for template not found
1765817658
self.assertIn("status_code=404", source)
17659-
self.assertIn("Template not found", source)
17659+
self.assertIn("ERR_TEMPLATE_NOT_FOUND", source)
1766017660
# Should have 1 inner try-catch for JSON parsing
1766117661
try_count = source.count("try:")
1766217662
self.assertEqual(try_count, 1, "Should have 1 inner try-catch for JSON parsing")

autobot-backend/api/knowledge_metadata.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import logging
1818

19+
from constants.error_constants import ERR_TEMPLATE_NOT_FOUND
1920
from fastapi import APIRouter, Depends, HTTPException
2021

2122
from api.knowledge_models import (
@@ -127,7 +128,7 @@ async def get_metadata_template(template_id: str):
127128
result = await kb.get_metadata_template(template_id)
128129

129130
if result.get("status") != "success":
130-
raise HTTPException(status_code=404, detail="Template not found")
131+
raise HTTPException(status_code=404, detail=ERR_TEMPLATE_NOT_FOUND)
131132

132133
return result
133134

autobot-backend/constants/__init__.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,10 @@
1717
ERR_INVALID_CREDENTIALS,
1818
ERR_INVALID_TOKEN,
1919
ERR_JOB_NOT_FOUND,
20-
ERR_NOT_FOUND,
2120
ERR_PATH_NOT_FOUND,
2221
ERR_SESSION_NOT_FOUND,
2322
ERR_TEMPLATE_NOT_FOUND,
2423
ERR_WORKFLOW_NOT_FOUND,
25-
ERR_FAILED_TO,
2624
)
2725
from .network_constants import ( # Legacy compatibility exports
2826
BACKEND_URL,
@@ -140,7 +138,6 @@
140138
"CategoryDefaults",
141139
"ProtocolDefaults",
142140
# Issue #3530: Error message string constants
143-
"ERR_NOT_FOUND",
144141
"ERR_ASSESSMENT_NOT_FOUND",
145142
"ERR_SESSION_NOT_FOUND",
146143
"ERR_FILE_NOT_FOUND",
@@ -153,7 +150,6 @@
153150
"ERR_WORKFLOW_NOT_FOUND",
154151
"ERR_INVALID_CREDENTIALS",
155152
"ERR_INVALID_TOKEN",
156-
"ERR_FAILED_TO",
157153
# Issue #3531: API path constants
158154
"PATH_API_HEALTH",
159155
"PATH_HEALTH",

autobot-backend/constants/error_constants.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
# Author: mrveiss
44
"""Shared error message string constants for HTTP responses and logging."""
55

6-
# Generic resource errors (use as: ERR_NOT_FOUND.format(resource='Workflow')}")
7-
ERR_NOT_FOUND = "{resource} not found"
8-
96
# Specific resource errors (pre-formatted for common cases)
107
ERR_ASSESSMENT_NOT_FOUND = "Assessment not found"
118
ERR_SESSION_NOT_FOUND = "Session not found"
@@ -21,6 +18,3 @@
2118
# Auth errors
2219
ERR_INVALID_CREDENTIALS = "Invalid username or password"
2320
ERR_INVALID_TOKEN = "Invalid token"
24-
25-
# Operation errors — use as f-string prefix at call site
26-
ERR_FAILED_TO = "Failed to {operation}"

autobot-backend/services/autoresearch/routes.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from pydantic import BaseModel, Field
1818

1919
from auth_middleware import check_admin_permission
20+
from constants.error_constants import ERR_SESSION_NOT_FOUND
2021
from constants.ttl_constants import TTL_24_HOURS
2122

2223
from .config import AutoResearchConfig
@@ -339,7 +340,7 @@ async def get_variants(
339340
key = f"autoresearch:prompt_opt:session:{session_id}"
340341
raw = await redis.get(key)
341342
if raw is None:
342-
raise HTTPException(status_code=404, detail="Session not found")
343+
raise HTTPException(status_code=404, detail=ERR_SESSION_NOT_FOUND)
343344
data = _json.loads(raw)
344345
return {"variants": data.get("all_variants", [])}
345346

0 commit comments

Comments
 (0)