Skip to content

Commit

Permalink
Improved API to return better message/code on errors
Browse files Browse the repository at this point in the history
  • Loading branch information
morpheus65535 committed Aug 24, 2022
1 parent 2c8a602 commit c2c0cbd
Show file tree
Hide file tree
Showing 14 changed files with 28 additions and 27 deletions.
2 changes: 1 addition & 1 deletion bazarr/api/episodes/blacklist.py
Expand Up @@ -64,7 +64,7 @@ def post(self):
.get_or_none()

if not episodeInfo:
return 'Episode not found', 500
return 'Episode not found', 404

media_path = episodeInfo['path']
subtitles_path = request.form.get('subtitles_path')
Expand Down
2 changes: 1 addition & 1 deletion bazarr/api/episodes/episodes.py
Expand Up @@ -22,7 +22,7 @@ def get(self):
.order_by(TableEpisodes.season.desc(), TableEpisodes.episode.desc())\
.dicts()
else:
return "Series or Episode ID not provided", 400
return "Series or Episode ID not provided", 404

result = list(result)
for item in result:
Expand Down
6 changes: 3 additions & 3 deletions bazarr/api/episodes/episodes_subtitles.py
Expand Up @@ -39,7 +39,7 @@ def patch(self):
.get_or_none()

if not episodeInfo:
return 'Episode not found', 500
return 'Episode not found', 404

title = episodeInfo['title']
episodePath = path_mappings.path_replace(episodeInfo['path'])
Expand Down Expand Up @@ -98,7 +98,7 @@ def post(self):
.get_or_none()

if not episodeInfo:
return 'Episode not found', 500
return 'Episode not found', 404

title = episodeInfo['title']
episodePath = path_mappings.path_replace(episodeInfo['path'])
Expand Down Expand Up @@ -164,7 +164,7 @@ def delete(self):
.get_or_none()

if not episodeInfo:
return 'Episode not found', 500
return 'Episode not found', 404

episodePath = path_mappings.path_replace(episodeInfo['path'])

Expand Down
2 changes: 1 addition & 1 deletion bazarr/api/movies/blacklist.py
Expand Up @@ -60,7 +60,7 @@ def post(self):
data = TableMovies.select(TableMovies.path).where(TableMovies.radarrId == radarr_id).dicts().get_or_none()

if not data:
return 'Movie not found', 500
return 'Movie not found', 404

media_path = data['path']
subtitles_path = request.form.get('subtitles_path')
Expand Down
4 changes: 2 additions & 2 deletions bazarr/api/movies/movies.py
Expand Up @@ -49,7 +49,7 @@ def post(self):
try:
profileId = int(profileId)
except Exception:
return '', 400
return 'Languages profile not found', 404

TableMovies.update({
TableMovies.profileId: profileId
Expand Down Expand Up @@ -79,4 +79,4 @@ def patch(self):
wanted_search_missing_subtitles_movies()
return '', 204

return '', 400
return 'Unknown action', 400
6 changes: 3 additions & 3 deletions bazarr/api/movies/movies_subtitles.py
Expand Up @@ -39,7 +39,7 @@ def patch(self):
.get_or_none()

if not movieInfo:
return 'Movie not found', 500
return 'Movie not found', 404

moviePath = path_mappings.path_replace_movie(movieInfo['path'])
sceneName = movieInfo['sceneName'] or 'None'
Expand Down Expand Up @@ -99,7 +99,7 @@ def post(self):
.get_or_none()

if not movieInfo:
return 'Movie not found', 500
return 'Movie not found', 404

moviePath = path_mappings.path_replace_movie(movieInfo['path'])
sceneName = movieInfo['sceneName'] or 'None'
Expand Down Expand Up @@ -161,7 +161,7 @@ def delete(self):
.get_or_none()

if not movieInfo:
return 'Movie not found', 500
return 'Movie not found', 404

moviePath = path_mappings.path_replace_movie(movieInfo['path'])

Expand Down
2 changes: 1 addition & 1 deletion bazarr/api/providers/providers.py
Expand Up @@ -50,4 +50,4 @@ def post(self):
reset_throttled_providers()
return '', 204

return '', 400
return 'Unknown action', 400
4 changes: 2 additions & 2 deletions bazarr/api/providers/providers_episodes.py
Expand Up @@ -30,7 +30,7 @@ def get(self):
.get_or_none()

if not episodeInfo:
return 'Episode not found', 500
return 'Episode not found', 404

title = episodeInfo['title']
episodePath = path_mappings.path_replace(episodeInfo['path'])
Expand Down Expand Up @@ -58,7 +58,7 @@ def post(self):
.get_or_none()

if not episodeInfo:
return 'Episode not found', 500
return 'Episode not found', 404

title = episodeInfo['title']
episodePath = path_mappings.path_replace(episodeInfo['path'])
Expand Down
4 changes: 2 additions & 2 deletions bazarr/api/providers/providers_movies.py
Expand Up @@ -31,7 +31,7 @@ def get(self):
.get_or_none()

if not movieInfo:
return 'Movie not found', 500
return 'Movie not found', 404

title = movieInfo['title']
moviePath = path_mappings.path_replace_movie(movieInfo['path'])
Expand All @@ -58,7 +58,7 @@ def post(self):
.get_or_none()

if not movieInfo:
return 'Movie not found', 500
return 'Movie not found', 404

title = movieInfo['title']
moviePath = path_mappings.path_replace_movie(movieInfo['path'])
Expand Down
4 changes: 2 additions & 2 deletions bazarr/api/series/series.py
Expand Up @@ -75,7 +75,7 @@ def post(self):
try:
profileId = int(profileId)
except Exception:
return '', 400
return 'Languages profile not found', 404

TableShows.update({
TableShows.profileId: profileId
Expand Down Expand Up @@ -113,4 +113,4 @@ def patch(self):
wanted_search_missing_subtitles_series()
return '', 204

return '', 400
return 'Unknown action', 400
4 changes: 2 additions & 2 deletions bazarr/api/subtitles/subtitles.py
Expand Up @@ -37,14 +37,14 @@ def patch(self):
.get_or_none()

if not metadata:
return 'Episode not found', 500
return 'Episode not found', 404

video_path = path_mappings.path_replace(metadata['path'])
else:
metadata = TableMovies.select(TableMovies.path).where(TableMovies.radarrId == id).dicts().get_or_none()

if not metadata:
return 'Movie not found', 500
return 'Movie not found', 404

video_path = path_mappings.path_replace_movie(metadata['path'])

Expand Down
4 changes: 2 additions & 2 deletions bazarr/api/system/account.py
Expand Up @@ -12,7 +12,7 @@
class SystemAccount(Resource):
def post(self):
if settings.auth.type != 'form':
return '', 405
return 'Unknown authentication type define in config.ini', 404

action = request.args.get('action')
if action == 'login':
Expand All @@ -26,4 +26,4 @@ def post(self):
gc.collect()
return '', 204

return '', 401
return 'Unknown action', 400
4 changes: 2 additions & 2 deletions bazarr/api/system/backups.py
Expand Up @@ -26,7 +26,7 @@ def patch(self):
restored = prepare_restore(filename)
if restored:
return '', 204
return '', 501
return 'Filename not provided', 400

@authenticate
def delete(self):
Expand All @@ -35,4 +35,4 @@ def delete(self):
deleted = delete_backup_file(filename)
if deleted:
return '', 204
return '', 501
return 'Filename not provided', 400
7 changes: 4 additions & 3 deletions bazarr/api/webhooks/plex.py
Expand Up @@ -39,7 +39,7 @@ def post(self):
if len(splitted_id) == 2:
ids.append({splitted_id[0]: splitted_id[1]})
if not ids:
return '', 404
return 'No GUID found', 400

if media_type == 'episode':
try:
Expand All @@ -53,7 +53,7 @@ def post(self):
series_imdb_id = show_metadata_dict['props']['pageProps']['aboveTheFoldData']['series']['series']['id']
except Exception:
logging.debug('BAZARR is unable to get series IMDB id.')
return '', 404
return 'IMDB series ID not found', 404
else:
sonarrEpisodeId = TableEpisodes.select(TableEpisodes.sonarrEpisodeId) \
.join(TableShows, on=(TableEpisodes.sonarrSeriesId == TableShows.sonarrSeriesId)) \
Expand All @@ -69,7 +69,8 @@ def post(self):
try:
movie_imdb_id = [x['imdb'] for x in ids if 'imdb' in x][0]
except Exception:
return '', 404
logging.debug('BAZARR is unable to get movie IMDB id.')
return 'IMDB movie ID not found', 404
else:
radarrId = TableMovies.select(TableMovies.radarrId)\
.where(TableMovies.imdbId == movie_imdb_id)\
Expand Down

0 comments on commit c2c0cbd

Please sign in to comment.