Skip to content

Commit

Permalink
Add the URL to the ClientResponseError repr string
Browse files Browse the repository at this point in the history
  • Loading branch information
dkliban authored and asvetlov committed Aug 10, 2019
1 parent df30472 commit 38a1ec4
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGES/3959.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add URL to the string representation of ClientResponseError.
1 change: 1 addition & 0 deletions CONTRIBUTORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ David Bibb
David Michael Brown
Denilson Amorim
Denis Matiychuk
Dennis Kliban
Dima Veselov
Dimitar Dimitrov
Diogo Dutra da Mata
Expand Down
3 changes: 2 additions & 1 deletion aiohttp/client_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ def __init__(self, request_info: RequestInfo,
self.headers = headers
self.history = history

super().__init__("%s, message='%s'" % (self.status, message))
super().__init__("%s, message='%s', url='%s" %
(self.status, message, request_info.real_url))


class ContentTypeError(ClientResponseError):
Expand Down
8 changes: 6 additions & 2 deletions tests/test_client_exceptions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Tests for client_exceptions.py"""

from unittest import mock

from yarl import URL

from aiohttp import client
Expand All @@ -21,13 +23,15 @@ def test_invalid_url() -> None:


def test_response_default_status() -> None:
request_info = mock.Mock(real_url='http://example.com')
err = client.ClientResponseError(history=None,
request_info=None)
request_info=request_info)
assert err.status == 0


def test_response_status() -> None:
request_info = mock.Mock(real_url='http://example.com')
err = client.ClientResponseError(status=400,
history=None,
request_info=None)
request_info=request_info)
assert err.status == 400

0 comments on commit 38a1ec4

Please sign in to comment.