Skip to content

Commit 5a5a29d

Browse files
authored
Merge pull request #798 from GDATASoftwareAG/python-raise-on-http-error
Python: Raise if upload fails
2 parents 8b6cc0f + f397a16 commit 5a5a29d

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

python/src/vaas/vaas.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,11 @@ def map_response(verdict_response) -> VaasVerdict:
120120
"MimeType": verdict_response.get("mime_type")
121121
}
122122

123+
def raiseIfHttpResponseError(response):
124+
if response.is_server_error:
125+
raise VaasServerError(response.reason_phrase)
126+
if response.is_client_error:
127+
raise VaasClientError(response.reason_phrase)
123128

124129
class Vaas:
125130
"""Verdict-as-a-Service client"""
@@ -379,7 +384,7 @@ async def __upload(self, token, upload_uri, buffer_or_file, content_length):
379384
jwt = PyJWT()
380385
decoded_token = jwt.decode(token, options={"verify_signature": False})
381386
try:
382-
await self.httpx_client.put(
387+
response = await self.httpx_client.put(
383388
url=upload_uri,
384389
content=buffer_or_file,
385390
headers={
@@ -388,6 +393,7 @@ async def __upload(self, token, upload_uri, buffer_or_file, content_length):
388393
},
389394
timeout=UPLOAD_TIMEOUT,
390395
)
396+
raiseIfHttpResponseError(response)
391397
except httpx.TimeoutException as ex:
392398
self.tracing.trace_upload_timeout(content_length)
393399
raise VaasTimeoutError() from ex

0 commit comments

Comments
 (0)