Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
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
10 changes: 8 additions & 2 deletions gidgethub/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
__version__ = "5.4.0.dev"

import http
from typing import Any, Optional
from typing import Any, Mapping, Optional


class GitHubException(Exception):
Expand All @@ -19,8 +19,14 @@ class ValidationFailure(GitHubException):
class HTTPException(GitHubException):
"""A general exception to represent HTTP responses."""

def __init__(self, status_code: http.HTTPStatus, *args: Any) -> None:
def __init__(
self,
status_code: http.HTTPStatus,
*args: Any,
headers: Optional[Mapping[str, str | None]] = None,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type for the headers doesn't line up with what decipher_response(), but they probably should.

Suggested change
headers: Optional[Mapping[str, str | None]] = None,
headers: Optional[Mapping[str, str]] = None,

Probably a better solution, though, would be a TypeVar that is used in both places.

) -> None:
self.status_code = status_code
self.headers = headers or {}
if args:
super().__init__(*args)
else:
Expand Down
2 changes: 1 addition & 1 deletion gidgethub/sansio.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ def decipher_response(
args = status_code_enum, message
else:
args = (status_code_enum,)
raise exc_type(*args)
raise exc_type(*args, headers=headers)


DOMAIN = "https://api.github.com"
Expand Down
4 changes: 3 additions & 1 deletion tests/test_sansio.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,8 +416,10 @@ def test_422_html_response(self):
def test_3XX(self):
status_code = 301
with pytest.raises(RedirectionException) as exc_info:
sansio.decipher_response(status_code, {}, b"")
headers = {"location": "https://api.github.com/test"}
sansio.decipher_response(status_code, headers, b"")
assert exc_info.value.status_code == http.HTTPStatus(status_code)
assert exc_info.value.headers == headers

def test_2XX_error(self):
status_code = 205
Expand Down