Skip to content

Commit 04345f0

Browse files
rakduttarakdutta1
andauthored
Improve Error Message for REST Tool Creation – Replace "Validation Failed" with Detailed Response (#675)
* tool Signed-off-by: RAKHI DUTTA <[email protected]> * tools Signed-off-by: RAKHI DUTTA <[email protected]> * main revert Signed-off-by: RAKHI DUTTA <[email protected]> * main revert Signed-off-by: RAKHI DUTTA <[email protected]> --------- Signed-off-by: RAKHI DUTTA <[email protected]> Co-authored-by: RAKHI DUTTA <[email protected]>
1 parent b7efba5 commit 04345f0

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

mcpgateway/utils/error_formatter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def format_validation_error(error: ValidationError) -> Dict[str, Any]:
8383
... result = ErrorFormatter.format_validation_error(e)
8484
<class 'pydantic_core._pydantic_core.ValidationError'>
8585
>>> result['message']
86-
'Validation failed'
86+
'Validation failed: Name must start with a letter and contain only letters, numbers, and underscores'
8787
>>> result['success']
8888
False
8989
>>> len(result['details']) > 0
@@ -134,7 +134,7 @@ def format_validation_error(error: ValidationError) -> Dict[str, Any]:
134134
# Log the full error for debugging
135135
logger.debug(f"Validation error: {error}")
136136

137-
return {"message": "Validation failed", "details": errors, "success": False}
137+
return {"message": f"Validation failed: {user_message}", "details": errors, "success": False}
138138

139139
@staticmethod
140140
def _get_user_message(field: str, technical_msg: str) -> str:

tests/unit/mcpgateway/utils/test_error_formatter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def test_format_validation_error_letter_requirement():
7171
with pytest.raises(ValidationError) as exc:
7272
NameModel(name="Bobby")
7373
result = ErrorFormatter.format_validation_error(exc.value)
74-
assert result["message"] == "Validation failed"
74+
assert result["message"] == "Validation failed: Name must start with a letter and contain only letters, numbers, and underscores"
7575
assert result["success"] is False
7676
assert result["details"][0]["field"] == "name"
7777
assert "must start with a letter" in result["details"][0]["message"]

0 commit comments

Comments
 (0)