mirror of
https://github.com/status-im/PyGithub.git
synced 2026-08-31 10:51:14 +00:00
Add retry issue to GithubException, don't log it (#2611)
This commit is contained in:
+22
-5
@@ -112,7 +112,19 @@ class GithubRetry(Retry):
|
||||
content = self.get_content(response, url)
|
||||
content = json.loads(content)
|
||||
message = content.get("message")
|
||||
except Exception as e:
|
||||
# we want to fall back to the actual github exception (probably a rate limit error)
|
||||
# but provide some context why we could not deal with it without another exception
|
||||
try:
|
||||
raise RuntimeError(
|
||||
"Failed to inspect response message"
|
||||
) from e
|
||||
except RuntimeError as e:
|
||||
raise GithubException(
|
||||
response.status, content, response.headers
|
||||
) from e
|
||||
|
||||
try:
|
||||
if Requester.isRateLimitError(message):
|
||||
rate_type = (
|
||||
"primary"
|
||||
@@ -191,11 +203,16 @@ class GithubRetry(Retry):
|
||||
except (MaxRetryError, GithubException):
|
||||
raise
|
||||
except Exception as e:
|
||||
self.__log(
|
||||
logging.WARNING,
|
||||
"Failed to inspect response message",
|
||||
exc_info=e,
|
||||
)
|
||||
# we want to fall back to the actual github exception (probably a rate limit error)
|
||||
# but provide some context why we could not deal with it without another exception
|
||||
try:
|
||||
raise RuntimeError(
|
||||
"Failed to determine retry backoff"
|
||||
) from e
|
||||
except RuntimeError as e:
|
||||
raise GithubException(
|
||||
response.status, content, response.headers
|
||||
) from e
|
||||
|
||||
raise GithubException(response.status, content, response.headers)
|
||||
|
||||
|
||||
+13
-10
@@ -20,6 +20,7 @@
|
||||
# #
|
||||
################################################################################
|
||||
import contextlib
|
||||
import logging
|
||||
import sys
|
||||
import unittest
|
||||
from datetime import datetime
|
||||
@@ -406,15 +407,17 @@ class GithubRetry(unittest.TestCase):
|
||||
self.assertEqual("NOT GOOD", exp.exception.data)
|
||||
self.assertEqual({}, exp.exception.headers)
|
||||
|
||||
self.assertListEqual(
|
||||
[
|
||||
(20, "Request TEST URL failed with 403: NOT GOOD"),
|
||||
(30, "Failed to inspect response message"),
|
||||
],
|
||||
[call[1] for call in log.mock_calls],
|
||||
)
|
||||
self.assertIsInstance(exp.exception.__cause__, RuntimeError)
|
||||
self.assertEqual(
|
||||
("Failed to inspect response message",), exp.exception.__cause__.args
|
||||
)
|
||||
|
||||
self.assertListEqual(
|
||||
[{}, {"exc_info": "Unable to determine whether fp is closed."}],
|
||||
[{k: str(v) for k, v in call[2].items()} for call in log.mock_calls],
|
||||
self.assertIsInstance(exp.exception.__cause__.__cause__, ValueError)
|
||||
self.assertEqual(
|
||||
("Unable to determine whether fp is closed.",),
|
||||
exp.exception.__cause__.__cause__.args,
|
||||
)
|
||||
|
||||
log.assert_called_once_with(
|
||||
logging.INFO, "Request TEST URL failed with 403: NOT GOOD"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user