Skip to content

Commit dc25724

Browse files
committed
Make it better
1 parent fa39b65 commit dc25724

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

sdk/core/azure-core/azure/core/pipeline/transport/_base.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,13 @@ def format_url(self, url_template, **kwargs):
730730
parsed = urlparse(url)
731731
if not parsed.scheme or not parsed.netloc:
732732
url = url.lstrip("/")
733-
base = _format_url_section(self._base_url, **kwargs).rstrip("/")
733+
try:
734+
base = self._base_url.format(**kwargs).rstrip("/")
735+
except KeyError as key:
736+
raise ValueError(
737+
"The value provided for the url part {} was incorrect, and resulted in an invalid url".format(key.args[0])
738+
)
739+
734740
url = _urljoin(base, url)
735741
else:
736742
url = self._base_url.format(**kwargs)

sdk/core/azure-core/tests/test_pipeline.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,9 @@ def test_format_url_no_base_url(self):
207207
def test_format_incorrect_endpoint(self):
208208
# https://github.com/Azure/azure-sdk-for-python/pull/12106
209209
client = PipelineClientBase('{Endpoint}/text/analytics/v3.0')
210-
formatted = client.format_url("foo/bar")
211-
# We don't care about the value, we care it doesn't fail
212-
assert formatted is not None
210+
with pytest.raises(ValueError) as exp:
211+
client.format_url("foo/bar")
212+
assert str(exp.value) == "The value provided for the url part Endpoint was incorrect, and resulted in an invalid url"
213213

214214
class TestClientRequest(unittest.TestCase):
215215
def test_request_json(self):

0 commit comments

Comments
 (0)