Skip to content

Commit 00b56d7

Browse files
committed
refactor: implement PR suggestions
1 parent 7a51de1 commit 00b56d7

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

‎src/sap_cloud_sdk/core/protocol/http/models.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import requests
1414
from oauthlib.oauth2 import BackendApplicationClient
15+
from oauthlib.oauth2.rfc6749.errors import FatalClientError
1516
from requests_oauthlib import OAuth2Session
1617

1718
from sap_cloud_sdk.core._tenant import (
@@ -136,6 +137,8 @@ def _fetch_token(self, tenant_subdomain: Optional[str]) -> OAuth2Session:
136137
)
137138
last_exc = None
138139
break
140+
except FatalClientError:
141+
raise
139142
except Exception as exc:
140143
last_exc = exc
141144
if attempt < _TOKEN_FETCH_MAX_ATTEMPTS - 1:

‎tests/core/unit/test_http_client.py‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
from unittest.mock import MagicMock, call, patch
44

5+
from oauthlib.oauth2.rfc6749.errors import InvalidClientError
6+
57
import pytest
68
import requests
79

@@ -382,3 +384,16 @@ def test_no_sleep_after_final_attempt(self):
382384
with pytest.raises(RuntimeError):
383385
provider._fetch_token(None)
384386
assert mock_sleep.call_count == 2 # only after attempts 1 and 2, not 3
387+
388+
def test_fatal_client_error_raises_immediately_without_retry(self):
389+
provider = self._make_provider()
390+
fatal = InvalidClientError()
391+
with patch("sap_cloud_sdk.core.protocol.http.models.OAuth2Session") as mock_cls, \
392+
patch("sap_cloud_sdk.core.protocol.http.models.time.sleep") as mock_sleep:
393+
mock_session = MagicMock()
394+
mock_cls.return_value = mock_session
395+
mock_session.fetch_token.side_effect = fatal
396+
with pytest.raises(InvalidClientError):
397+
provider._fetch_token(None)
398+
assert mock_session.fetch_token.call_count == 1
399+
mock_sleep.assert_not_called()

0 commit comments

Comments
 (0)