Skip to content

Commit 7f26810

Browse files
cfsmp3claude
andcommitted
fix: Address review comments - don't expose exception details
- Log database exceptions server-side with g.log.exception() - Return generic "Database connection failed" message to client - Add comment explaining db.remove() connection pool cleanup - Update test to expect generic error message 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 1917bae commit 7f26810

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

mod_health/controllers.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from datetime import datetime
44
from typing import Any, Dict, Tuple
55

6-
from flask import Blueprint, current_app, jsonify
6+
from flask import Blueprint, current_app, g, jsonify
77

88
mod_health = Blueprint('health', __name__)
99

@@ -19,10 +19,12 @@ def check_database() -> Dict[str, Any]:
1919
from database import create_session
2020
db = create_session(current_app.config['DATABASE_URI'])
2121
db.execute('SELECT 1')
22+
# remove() returns the scoped session's connection to the pool
2223
db.remove()
2324
return {'status': 'ok'}
2425
except Exception as e:
25-
return {'status': 'error', 'message': str(e)}
26+
g.log.exception('Health check database connection failed')
27+
return {'status': 'error', 'message': 'Database connection failed'}
2628

2729

2830
def check_config() -> Dict[str, Any]:

tests/test_health/test_controllers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ def test_check_database_failure(self):
109109
mock_session.side_effect = Exception('Connection refused')
110110
result = check_database()
111111
self.assertEqual(result['status'], 'error')
112-
self.assertIn('Connection refused', result['message'])
112+
# Generic message returned (actual exception logged server-side)
113+
self.assertEqual(result['message'], 'Database connection failed')
113114

114115
def test_check_config_success(self):
115116
"""Test check_config returns ok when config is complete."""

0 commit comments

Comments
 (0)