Skip to content

Commit 89d0ae5

Browse files
authored
Merge pull request #65 from virtUOS/http-exc-logs
Don't log stack traces on HTTP errors
2 parents 453638a + f122099 commit 89d0ae5

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

occameracontrol/metrics.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
# along with this program. If not, see <https://www.gnu.org/licenses/>.
1616

1717
import logging
18+
import requests
1819
import time
1920

2021
from confygure import config_t
@@ -50,6 +51,10 @@ class RequestErrorHandler():
5051
the error from propagating any further.
5152
'''
5253

54+
err_msg_only = (
55+
requests.exceptions.ConnectionError,
56+
requests.exceptions.HTTPError)
57+
5358
def __init__(self, resource, message):
5459
'''Create a RequestErrorHandler instance.
5560
@@ -66,7 +71,10 @@ def __exit__(self, exc_type, exc_value, traceback):
6671
'''Handler for then exiting the `with` block. Takes care of catching
6772
errors, logging them and updating the metrics.
6873
'''
69-
if exc_type:
74+
if exc_type in self.err_msg_only:
75+
logger.error('%s: %s', self.message, exc_value)
76+
request_errors.labels(self.resource, exc_type.__name__).inc()
77+
elif exc_type:
7078
logger.exception(self.message)
7179
request_errors.labels(self.resource, exc_type.__name__).inc()
7280
# Silence Exception types

0 commit comments

Comments
 (0)