Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add raw response to DaprInternalError #628

Merged
merged 2 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion dapr/clients/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@ class DaprInternalError(Exception):
"""DaprInternalError encapsulates all Dapr exceptions"""
def __init__(
self, message: Optional[str],
error_code: Optional[str] = ERROR_CODE_UNKNOWN):
error_code: Optional[str] = ERROR_CODE_UNKNOWN,
raw_response_bytes: Optional[bytes] = None):
self._message = message
self._error_code = error_code
self._raw_response_bytes = raw_response_bytes

def as_dict(self):
return {
'message': self._message,
'errorCode': self._error_code,
'raw_response_bytes': self._raw_response_bytes
}
10 changes: 6 additions & 4 deletions dapr/clients/http/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,22 +98,24 @@

raise (await self.convert_to_error(r))

async def convert_to_error(self, response) -> DaprInternalError:
async def convert_to_error(self, response: aiohttp.ClientResponse) -> DaprInternalError:
error_info = None
try:
error_body = await response.read()
if (error_body is None or len(error_body) == 0) and response.status == 404:
return DaprInternalError("Not Found", ERROR_CODE_DOES_NOT_EXIST)
error_info = self._serializer.deserialize(error_body)
except Exception:
return DaprInternalError(f'Unknown Dapr Error. HTTP status code: {response.status}')
return DaprInternalError(f'Unknown Dapr Error. HTTP status code: {response.status}',
raw_response_bytes=error_body)

if error_info and isinstance(error_info, dict):
message = error_info.get('message')
error_code = error_info.get('errorCode') or ERROR_CODE_UNKNOWN
return DaprInternalError(message, error_code)
return DaprInternalError(message, error_code, raw_response_bytes=error_body)

return DaprInternalError(f'Unknown Dapr Error. HTTP status code: {response.status}')
return DaprInternalError(f'Unknown Dapr Error. HTTP status code: {response.status}',

Check warning on line 117 in dapr/clients/http/client.py

View check run for this annotation

Codecov / codecov/patch

dapr/clients/http/client.py#L117

Added line #L117 was not covered by tests
raw_response_bytes=error_body)

def get_ssl_context(self):
# This method is used (overwritten) from tests
Expand Down
Loading