Skip to content

Commit

Permalink
add raise_for_status from requests
Browse files Browse the repository at this point in the history
  • Loading branch information
rawandahmad698 committed Mar 2, 2024
1 parent a0547ab commit 97f0ea7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
8 changes: 8 additions & 0 deletions noble_tls/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from .cookies import cookiejar_from_dict
from noble_tls.utils.structures import CaseInsensitiveDict
from typing import Optional
from requests.exceptions import HTTPError


class Response:
Expand All @@ -28,6 +29,13 @@ def json(self, **kwargs) -> Union[Dict, list]:
"""Parses the text content of the response to JSON."""
return json.loads(self.text, **kwargs)

def raise_for_status(self):
"""Raises an HTTPError if the HTTP request returned an unsuccessful status code."""
if 400 <= self.status_code < 500:
raise HTTPError(f'Client Error: {self.status_code} for url: {self.url}')
elif 500 <= self.status_code < 600:
raise HTTPError(f'Server Error: {self.status_code} for url: {self.url}')

@property
def content(self) -> bytes:
"""Lazily loads the content of the response, in bytes."""
Expand Down
1 change: 0 additions & 1 deletion noble_tls/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@


class Session:

def __init__(
self,
client: Optional[Client] = None,
Expand Down

0 comments on commit 97f0ea7

Please sign in to comment.