4141| Exception | Cause |
4242|-----------|-------|
4343| [`JustWatchHttpError`][simplejustwatchapi.exceptions.JustWatchHttpError] | \
44- JustWatch API responded with non-`2xx` code. |
44+ HTTP error occurred, e.g., JustWatch API responded with non-`2xx` status code. |
4545| [`JustWatchApiError`][simplejustwatchapi.exceptions.JustWatchApiError] | \
46- JSON response from JustWatch API contains errors ( e.g., due to invalid language or \
47- country code). If this exception is raised, then API responded with `2xx` code . |
46+ JSON response from JustWatch API contains errors, e.g., due to invalid language or \
47+ country code. |
4848"""
4949
50- from httpx import post
50+ from httpx import HTTPError , post
5151
5252from simplejustwatchapi .exceptions import JustWatchHttpError
5353from simplejustwatchapi .query import (
@@ -154,7 +154,8 @@ def search(
154154 Raises:
155155 exceptions.JustWatchApiError: JSON response from API has internal errors, e.g.,
156156 due to invalid language or country code.
157- exceptions.JustWatchHttpError: JustWatch API didn't respond with `2xx` code.
157+ exceptions.JustWatchHttpError: HTTP error occurred, e.g., JustWatch API
158+ responded with non-`2xx` status code.
158159
159160 """
160161 request = prepare_search_request (
@@ -238,7 +239,8 @@ def popular(
238239 Raises:
239240 exceptions.JustWatchApiError: JSON response from API has internal errors, e.g.,
240241 due to invalid language or country code.
241- exceptions.JustWatchHttpError: JustWatch API didn't respond with `2xx` code.
242+ exceptions.JustWatchHttpError: HTTP error occurred, e.g., JustWatch API
243+ responded with non-`2xx` status code.
242244
243245 """
244246 request = prepare_popular_request (
@@ -307,7 +309,8 @@ def details(
307309 Raises:
308310 exceptions.JustWatchApiError: JSON response from API has internal errors, e.g.,
309311 due to invalid language or country code.
310- exceptions.JustWatchHttpError: JustWatch API didn't respond with `2xx` code.
312+ exceptions.JustWatchHttpError: HTTP error occurred, e.g., JustWatch API
313+ responded with non-`2xx` status code.
311314
312315 """
313316 request = prepare_details_request (node_id , country , language , best_only )
@@ -355,7 +358,8 @@ def seasons(
355358 Raises:
356359 exceptions.JustWatchApiError: JSON response from API has internal errors, e.g.,
357360 due to invalid language or country code.
358- exceptions.JustWatchHttpError: JustWatch API didn't respond with `2xx` code.
361+ exceptions.JustWatchHttpError: HTTP error occurred, e.g., JustWatch API
362+ responded with non-`2xx` status code.
359363
360364 """
361365 request = prepare_seasons_request (show_id , country , language , best_only )
@@ -404,7 +408,8 @@ def episodes(
404408 Raises:
405409 exceptions.JustWatchApiError: JSON response from API has internal errors, e.g.,
406410 due to invalid language or country code.
407- exceptions.JustWatchHttpError: JustWatch API didn't respond with `2xx` code.
411+ exceptions.JustWatchHttpError: HTTP error occurred, e.g., JustWatch API
412+ responded with non-`2xx` status code.
408413
409414 """
410415 request = prepare_episodes_request (season_id , country , language , best_only )
@@ -472,7 +477,8 @@ def offers_for_countries(
472477 Raises:
473478 exceptions.JustWatchApiError: JSON response from API has internal errors, e.g.,
474479 due to invalid language or country code.
475- exceptions.JustWatchHttpError: JustWatch API didn't respond with `2xx` code.
480+ exceptions.JustWatchHttpError: HTTP error occurred, e.g., JustWatch API
481+ responded with non-`2xx` status code.
476482
477483 """
478484 if not countries :
@@ -506,7 +512,8 @@ def providers(country: str = "US") -> list[OfferPackage]:
506512 Raises:
507513 exceptions.JustWatchApiError: JSON response from API has internal errors, e.g.,
508514 due to invalid language or country code.
509- exceptions.JustWatchHttpError: JustWatch API didn't respond with `2xx` code.
515+ exceptions.JustWatchHttpError: HTTP error occurred, e.g., JustWatch API
516+ responded with non-`2xx` status code.
510517
511518 """
512519 request = prepare_providers_request (country )
@@ -525,10 +532,12 @@ def _post_to_jw_graphql_api(request_json: dict) -> dict:
525532 (dict): JSON response from the API.
526533
527534 Raises:
528- exceptions.JustWatchHttpError: JustWatch API didn't respond with `2xx` code .
535+ exceptions.JustWatchHttpError: HTTP-related error occurred .
529536
530537 """
531- response = post (_GRAPHQL_API_URL , json = request_json )
532- if not response .is_success :
533- raise JustWatchHttpError (response .status_code , response .text )
538+ try :
539+ response = post (_GRAPHQL_API_URL , json = request_json )
540+ response .raise_for_status ()
541+ except HTTPError as e :
542+ raise JustWatchHttpError (str (e )) from e
534543 return response .json ()
0 commit comments