|
7 | 7 |
|
8 | 8 | import app
|
9 | 9 | from app.models import Media, MediaTypes, Sources
|
| 10 | +from app.providers import services |
10 | 11 | from integrations import helpers
|
11 | 12 | from integrations.helpers import MediaImportError, MediaImportUnexpectedError
|
12 | 13 |
|
@@ -42,8 +43,8 @@ def get_token(request):
|
42 | 43 | headers=headers,
|
43 | 44 | params=params,
|
44 | 45 | )
|
45 |
| - except requests.exceptions.HTTPError as error: |
46 |
| - if error.response.status_code == requests.codes.unauthorized: |
| 46 | + except services.ProviderAPIError as error: |
| 47 | + if error.status_code == requests.codes.unauthorized: |
47 | 48 | msg = "Invalid SIMKL secret key."
|
48 | 49 | raise MediaImportError(msg) from error
|
49 | 50 | raise
|
@@ -149,8 +150,8 @@ def process_tv_list(tv_list, user, bulk_media, warnings):
|
149 | 150 |
|
150 | 151 | try:
|
151 | 152 | metadata = app.providers.tmdb.tv_with_seasons(tmdb_id, season_numbers)
|
152 |
| - except requests.exceptions.HTTPError as error: |
153 |
| - if error.response.status_code == requests.codes.not_found: |
| 153 | + except services.ProviderAPIError as error: |
| 154 | + if error.status_code == requests.codes.not_found: |
154 | 155 | warnings.append(
|
155 | 156 | f"{title}: not found in {Sources.TMDB.label} "
|
156 | 157 | f"with ID {tmdb_id}.",
|
@@ -295,8 +296,8 @@ def process_movie_list(movie_list, user, bulk_media, warnings):
|
295 | 296 |
|
296 | 297 | try:
|
297 | 298 | metadata = app.providers.tmdb.movie(tmdb_id)
|
298 |
| - except requests.exceptions.HTTPError as error: |
299 |
| - if error.response.status_code == requests.codes.not_found: |
| 299 | + except services.ProviderAPIError as error: |
| 300 | + if error.status_code == requests.codes.not_found: |
300 | 301 | warnings.append(
|
301 | 302 | f"{title}: not found in {Sources.TMDB.label} "
|
302 | 303 | f"with ID {tmdb_id}.",
|
@@ -359,8 +360,8 @@ def process_anime_list(anime_list, user, bulk_media, warnings):
|
359 | 360 |
|
360 | 361 | try:
|
361 | 362 | metadata = app.providers.mal.anime(mal_id)
|
362 |
| - except requests.exceptions.HTTPError as error: |
363 |
| - if error.response.status_code == requests.codes.not_found: |
| 363 | + except services.ProviderAPIError as error: |
| 364 | + if error.status_code == requests.codes.not_found: |
364 | 365 | warnings.append(
|
365 | 366 | f"{title}: not found in {Sources.MAL.label} with ID {mal_id}.",
|
366 | 367 | )
|
|
0 commit comments