Skip to content

Commit

Permalink
Fixes #244
Browse files Browse the repository at this point in the history
  • Loading branch information
HardNorth committed Nov 29, 2024
1 parent 91733b5 commit 64e36a9
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Changelog

## [Unreleased]
### Fixed
- Issue [#244](https://github.com/reportportal/client-Python/issues/244): Client crash on different error responses, by @HardNorth

## [5.5.9]
### Fixed
Expand Down
7 changes: 6 additions & 1 deletion reportportal_client/core/rp_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"""

import asyncio
import json as json_converter
import logging
from dataclasses import dataclass
from typing import Callable, Optional, Union, List, Tuple, Any, TypeVar
Expand All @@ -43,6 +42,12 @@
from reportportal_client.core.rp_responses import RPResponse, AsyncRPResponse
from reportportal_client.helpers import dict_to_payload, await_if_necessary

try:
# noinspection PyPackageRequirements
import simplejson as json_converter
except ImportError:
import json as json_converter

logger = logging.getLogger(__name__)
T = TypeVar("T")

Expand Down
9 changes: 5 additions & 4 deletions reportportal_client/core/rp_responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import logging
from typing import Any, Optional, Generator, Mapping, Tuple, Union

from aiohttp import ClientResponse
from aiohttp import ClientResponse, ClientError
from requests import Response

# noinspection PyProtectedMember
Expand All @@ -41,8 +41,9 @@ def _iter_json_messages(json: Any) -> Generator[str, None, None]:


def _get_json_decode_error_message(response: Union[Response, ClientResponse]) -> str:
status = getattr(response, 'status', getattr(response, 'status_code'))
return f'Unable to decode JSON response, got {"passed" if response.ok else "failed"} ' \
status = getattr(response, 'status', getattr(response, 'status_code', None))
ok = getattr(response, 'ok', None)
return f'Unable to decode JSON response, got {"passed" if ok else "failed"} ' \
f'response with code "{status}" please check your endpoint configuration or API key'


Expand Down Expand Up @@ -155,7 +156,7 @@ async def json(self) -> Any:
if self.__json is NOT_SET:
try:
self.__json = await self._resp.json()
except (ValueError, TypeError) as exc:
except (ValueError, TypeError, ClientError) as exc:
logger.error(_get_json_decode_error_message(self._resp), exc_info=exc)
self.__json = None
return self.__json
Expand Down
7 changes: 6 additions & 1 deletion reportportal_client/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

import asyncio
import inspect
import json
import logging
import sys
import threading
Expand All @@ -27,6 +26,12 @@

from reportportal_client.core.rp_file import RPFile

try:
# noinspection PyPackageRequirements
import simplejson as json
except ImportError:
import json

logger: logging.Logger = logging.getLogger(__name__)
_T = TypeVar('_T')
ATTRIBUTE_LENGTH_LIMIT: int = 128
Expand Down

0 comments on commit 64e36a9

Please sign in to comment.