simple-justwatch-python-api 1.1.0__tar.gz → 1.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: simple-justwatch-python-api
3
- Version: 1.1.0
3
+ Version: 1.2.0
4
4
  Summary: A simple JustWatch Python API
5
5
  Keywords: justwatch,api,graphql
6
6
  Author: Electronic Mango
@@ -3,7 +3,7 @@ name = "simple-justwatch-python-api"
3
3
  authors = [
4
4
  { name = "Electronic Mango", email = "78230210+Electronic-Mango@users.noreply.github.com" },
5
5
  ]
6
- version = "1.1.0"
6
+ version = "1.2.0"
7
7
  description = "A simple JustWatch Python API"
8
8
  readme = "README.md"
9
9
  license = "MIT"
@@ -40,4 +40,15 @@ class JustWatchHttpError(JustWatchError):
40
40
 
41
41
  This is a general exception for any HTTP-related errors, such as non-`2xx` status
42
42
  codes, network errors, timeouts, etc.
43
+
44
+ Attributes:
45
+ msg (str): Error message describing the HTTP error.
46
+ response (str | None): Optional text of the HTTP response, if available.
47
+ Usucally contains JSON with error responses from the API.
48
+
43
49
  """
50
+
51
+ def __init__(self, msg: str, response: str | None = None) -> None:
52
+ """Init JustWatchHttpError with error message and optional response text."""
53
+ super().__init__(msg)
54
+ self.response = response
@@ -47,7 +47,7 @@ Each function can raise two exceptions:
47
47
  country code. |
48
48
  """
49
49
 
50
- from httpx import HTTPError, post
50
+ from httpx import HTTPError, HTTPStatusError, post
51
51
 
52
52
  from simplejustwatchapi.exceptions import JustWatchHttpError
53
53
  from simplejustwatchapi.query import (
@@ -538,6 +538,8 @@ def _post_to_jw_graphql_api(request_json: dict) -> dict:
538
538
  try:
539
539
  response = post(_GRAPHQL_API_URL, json=request_json)
540
540
  response.raise_for_status()
541
+ return response.json()
542
+ except HTTPStatusError as e:
543
+ raise JustWatchHttpError(str(e), e.response.text) from e
541
544
  except HTTPError as e:
542
545
  raise JustWatchHttpError(str(e)) from e
543
- return response.json()