Skip to content

Commit

Permalink
Fixed broken tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nekokatt committed Sep 23, 2020
1 parent ebe6bab commit 99d1fd9
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
2 changes: 1 addition & 1 deletion hikari/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ class HTTPClientClosedError(HTTPError):


@typing.final
class RESTErrorCode(str, enums.Enum):
class RESTErrorCode(int, enums.Enum):
"""Error codes provided as further info on errors returned by the REST API."""

GENERAL_ERROR = 0
Expand Down
12 changes: 4 additions & 8 deletions hikari/utilities/net.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ async def generate_error_response(response: aiohttp.ClientResponse) -> errors.HT
json_body = await response.json()
args.append(json_body.get("message", ""))
args.append(errors.RESTErrorCode(json_body.get("code", 0)))

except (aiohttp.ContentTypeError):
except aiohttp.ContentTypeError:
pass

if response.status == http.HTTPStatus.BAD_REQUEST:
Expand All @@ -63,15 +62,12 @@ async def generate_error_response(response: aiohttp.ClientResponse) -> errors.HT

status = http.HTTPStatus(response.status)

cls: typing.Type[errors.HikariError]
if 400 <= status < 500:
cls = errors.ClientHTTPResponseError
return errors.ClientHTTPResponseError(real_url, status, response.headers, raw_body)
elif 500 <= status < 600:
cls = errors.InternalServerError
return errors.InternalServerError(real_url, status, response.headers, raw_body)
else:
cls = errors.HTTPResponseError

return cls(real_url, status, response.headers, raw_body)
return errors.HTTPResponseError(real_url, status, response.headers, raw_body)


def create_tcp_connector(
Expand Down
5 changes: 3 additions & 2 deletions tests/hikari/utilities/test_net.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,10 @@ async def json(self):
(http.HTTPStatus.NOT_FOUND, "NotFoundError"),
],
)
@pytest.mark.parametrize("json_response", [aiohttp.ContentTypeError(None, None), KeyError])
@pytest.mark.asyncio
async def test_generate_error_when_error_with_json(status_, expected_error, json_response):
async def test_generate_error_when_error_with_json(status_, expected_error):
json_response = aiohttp.ContentTypeError(None, None)

class StubResponse:
real_url = "https://some.url"
status = status_
Expand Down

0 comments on commit 99d1fd9

Please sign in to comment.