# Buggy code
def validate_show(show, season=None, episode=None):
    """Reindex show from originating indexer, and return indexer information for the passed episode."""
    from medusa.indexers.indexer_api import indexerApi
    from medusa.indexers.indexer_exceptions import (
        IndexerEpisodeNotFound,
        IndexerSeasonNotFound,
    )

    indexer_lang = show.lang

    try:
        indexer_api_params = indexerApi(show.indexer).api_params.copy()

        if indexer_lang and not indexer_lang == app.INDEXER_DEFAULT_LANGUAGE:
            indexer_api_params["language"] = indexer_lang

        if show.dvd_order != 0:
            indexer_api_params["dvdorder"] = True

        if season is None and episode is None:
            return show.indexer_api

        return show.indexer_api[show.indexerid][season][episode]
    except (IndexerEpisodeNotFound, IndexerSeasonNotFound):
        pass


# Traceback (HTTPError)
2017-04-26 03:38:38 INFO     TORRENTCHECKER :: [b99a467] Torrent did not reach minimum ratio: [0.685/4.000]. Keeping it: [The.Last.Man.On.Earth.S03E13.720p.HDTV.x264-AVS]
2017-04-26 03:38:38 INFO     TORRENTCHECKER :: [b99a467] Torrent did not reach minimum ratio: [0.272/4.000]. Keeping it: [top.gear.s24e05.720p.hdtv.x264-moritz.mkv]
2017-04-26 03:38:43 INFO     TORRENTCHECKER :: [b99a467] Torrent did not reach minimum ratio: [0.000/5.000]. Keeping it: [Panorama.2017.04.05.The.Benefits.Cap.Is.It.Working.720p.HDTV.x264-DEADPOOL]
2017-04-26 03:38:43 INFO     TORRENTCHECKER :: [b99a467] Torrent did not reach minimum ratio: [0.793/2.000]. Keeping it: [The.Simpsons.S28E15.1080p.Amazon.WEBRip.DD+.5.1.x264-TrollHD.mkv]
2017-04-26 03:38:43 INFO     TORRENTCHECKER :: [b99a467] Torrent completed and reached minimum ratio but it was force started again. Current ratio: [0.195/0.000]. Keeping it: [Red.Rock.S03E02.576p.TV3.WEBRip.AAC2.0.x264-HARiKEN.mkv]
2017-04-26 03:38:44 INFO     TORRENTCHECKER :: [b99a467] Torrent did not reach minimum ratio: [0.021/2.000]. Keeping it: [13.Reasons.Why.S01E01.1080p.WEBRip.X264-DEFLATE[hds]]
2017-04-26 03:38:48 INFO     TORRENTCHECKER :: [b99a467] Torrent did not reach minimum ratio: [0.159/5.000]. Keeping it: [Panorama.2017.04.03.Marine.Le.Pen.Whos.Funding.Frances.Far.Right.720p.HDTV.x264-DEADPOOL]
2017-04-26 03:38:52 WARNING  SHOWQUEUE-REFRESH :: [b99a467] Unable to find TVDBv2 show 311819, skipping it
2017-04-26 03:38:52 DEBUG    SHOWQUEUE-REFRESH :: [b99a467] Checking if /media/ssd/Shows/APB/season-all-poster.jpg exists: True
2017-04-26 03:38:52 DEBUG    SHOWQUEUE-REFRESH :: [b99a467] Checking if /media/ssd/Shows/APB/season-all-banner.jpg exists: True
2017-04-26 03:38:52 DEBUG    SHOWQUEUE-REFRESH :: [b99a467] Checking if /media/ssd/Shows/APB/tvshow.nfo exists: True
2017-04-26 03:38:52 DEBUG    SHOWQUEUE-REFRESH :: [b99a467] 311819: Writing NFOs for all episodes
2017-04-26 03:38:53 INFO     TORRENTCHECKER :: [b99a467] Torrent did not reach minimum ratio: [0.138/5.000]. Keeping it: [The.Last.Man.On.Earth.S03E14.720p.HDTV.x264-AVS]
2017-04-26 03:38:53 DEBUG    SHOWQUEUE-REFRESH :: [b99a467] 311819: Retrieving/creating episode S01E01
2017-04-26 03:38:53 DEBUG    SHOWQUEUE-REFRESH :: [b99a467] Checking if /media/ssd/Shows/APB/Season 01/APB.S01E01.Hard.Reset.1080p.WEB-KiMCHi.nfo exists: True
2017-04-26 03:38:53 DEBUG    SHOWQUEUE-REFRESH :: [b99a467] Checking if /media/ssd/Shows/APB/Season 01/APB.S01E01.Hard.Reset.1080p.WEB-KiMCHi-thumb.jpg exists: False
2017-04-26 03:38:53 DEBUG    SHOWQUEUE-REFRESH :: [b99a467] Matched release /media/ssd/Shows/APB/Season 01/APB.S01E01.Hard.Reset.1080p.WEB-KiMCHi to a series in your database: APB
2017-04-26 03:38:53 DEBUG    SHOWQUEUE-REFRESH :: [b99a467] Parsed /media/ssd/Shows/APB/Season 01/APB.S01E01.Hard.Reset.1080p.WEB-KiMCHi into title: APB, season: 1, episode: [1], episode_title: Hard Reset, screen_size: 1080p, format: WEB-DL, release_group: KiMCHi, type: episode, parsing_time: 0.362519025803, total_time: 0.362747192383, absolute_episode: [], quality: 1080p WEB-DL
2017-04-26 03:38:53 DEBUG    SHOWQUEUE-REFRESH :: [b99a467] Using cached parse result for APB.S01E01.Hard.Reset.1080p.WEB-KiMCHi
2017-04-26 03:38:53 DEBUG    SHOWQUEUE-REFRESH :: [b99a467] Found codec for APB Hard Reset
2017-04-26 03:38:53 DEBUG    SHOWQUEUE-REFRESH :: [b99a467] 311819: Formatting pattern: %SN - S%0SE%0E - %EN -> APB - S01E01 - Hard Reset
2017-04-26 03:38:53 DEBUG    SHOWQUEUE-REFRESH :: [b99a467] Metadata provider KODI 12+ creating episode thumbnail for APB - S01E01 - Hard Reset
2017-04-26 03:38:53 DEBUG    SHOWQUEUE-REFRESH :: [b99a467] Configured language en override show language of en
2017-04-26 03:38:53 DEBUG    SHOWQUEUE-REFRESH :: [b99a467] Getting all series data for 311819
2017-04-26 03:38:53 DEBUG    SHOWQUEUE-REFRESH :: [b99a467] Getting all show data for [311819]
2017-04-26 03:38:53 INFO     TORRENTCHECKER :: [b99a467] Torrent did not reach minimum ratio: [0.343/4.000]. Keeping it: [The.Simpsons.S28E19.1080p.Amazon.WEBRip.DD+.5.1.x264-TrollHD.mkv]
2017-04-26 03:38:53 INFO     TORRENTCHECKER :: [b99a467] Torrent did not reach minimum ratio: [0.000/4.000]. Keeping it: [panorama.2016.12.19.john.simpson.my.50.years.with.the.bbc.720p.hdtv.x264-plutonium.mkv]
2017-04-26 03:38:58 INFO     TORRENTCHECKER :: [b99a467] Torrent did not reach minimum ratio: [0.031/5.000]. Keeping it: [Taken.2017.S01E05.720p.HDTV.x264-KILLERS]
2017-04-26 03:39:06 INFO     TORRENTCHECKER :: [b99a467] Torrent not yet post-processed. Skipping: The.Son.S01E04.720p.HDTV.x264-AVS
2017-04-26 03:39:07 INFO     TORRENTCHECKER :: [b99a467] Torrent not yet post-processed. Skipping: The.Man.in.the.High.Castle.S02E10.Fallout.WEB.x264-PimpJuice219.mp4
2017-04-26 03:39:07 INFO     TORRENTCHECKER :: [b99a467] Torrent did not reach minimum ratio: [0.000/4.000]. Keeping it: [Family.Guy.S15E13.720p.HDTV.x264-FLEET.mkv]
2017-04-26 03:39:15 INFO     TORRENTCHECKER :: [b99a467] Torrent did not reach minimum ratio: [0.045/5.000]. Keeping it: [The.Gadget.Show.S27E03.720p.HDTV.x264-QPEL]
2017-04-26 03:39:22 INFO     TORRENTCHECKER :: [b99a467] Torrent did not reach minimum ratio: [0.010/5.000]. Keeping it: [24.Legacy.S01E11.720p.HDTV.x264-KILLERS]
2017-04-26 03:39:23 ERROR    SHOWQUEUE-REFRESH :: [b99a467] 311819: Error while refreshing show APB. Error: Show search failed in getting a result with reason: HTTPError
522 Server Error: Origin Connection Time-out for url: https://api.thetvdb.com/series/311819 (522)
Traceback (most recent call last):
  File "/home/pi/Medusa/medusa/show_queue.py", line 632, in run
    self.show.write_metadata()
  File "/home/pi/Medusa/medusa/tv/series.py", line 847, in write_metadata
    self.__write_episode_nfos()
  File "/home/pi/Medusa/medusa/tv/series.py", line 871, in __write_episode_nfos
    cur_ep.create_meta_files()
  File "/home/pi/Medusa/medusa/tv/episode.py", line 930, in create_meta_files
    self.__create_thumbnail(metadata_provider)
  File "/home/pi/Medusa/medusa/tv/episode.py", line 952, in __create_thumbnail
    result = metadata_provider.create_episode_thumb(self) or result
  File "/home/pi/Medusa/medusa/metadata/generic.py", line 324, in create_episode_thumb
    return self.save_thumbnail(ep_obj)
  File "/home/pi/Medusa/medusa/metadata/generic.py", line 498, in save_thumbnail
    thumb_url = self._get_episode_thumb_url(ep_obj)
  File "/home/pi/Medusa/medusa/metadata/generic.py", line 386, in _get_episode_thumb_url
    myEp = helpers.validate_show(cur_ep.show, cur_ep.season, cur_ep.episode)
  File "/home/pi/Medusa/medusa/helpers/__init__.py", line 1084, in validate_show
    return show.indexer_api[show.indexerid][season][episode]
  File "/home/pi/Medusa/medusa/indexers/indexer_base.py", line 254, in __getitem__
    self._get_show_data(key, self.config['language'])
  File "/home/pi/Medusa/medusa/indexers/tvdbv2/tvdbv2_api.py", line 536, in _get_show_data
    series_info = self._get_show_by_id(sid, request_language=get_show_in_language)
  File "/home/pi/Medusa/medusa/indexers/tvdbv2/tvdbv2_api.py", line 204, in _get_show_by_id
    .format(reason=e.reason, status=e.status)
IndexerShowNotFound: Show search failed in getting a result with reason: HTTPError
522 Server Error: Origin Connection Time-out for url: https://api.thetvdb.com/series/311819 (522)

# Fixed code
def validate_show(show, season=None, episode=None):
    """Reindex show from originating indexer, and return indexer information for the passed episode."""
    from medusa.indexers.indexer_api import indexerApi
    from medusa.indexers.indexer_exceptions import (
        IndexerEpisodeNotFound,
        IndexerSeasonNotFound,
        IndexerShowNotFound,
    )

    indexer_lang = show.lang

    try:
        indexer_api_params = indexerApi(show.indexer).api_params.copy()

        if indexer_lang and not indexer_lang == app.INDEXER_DEFAULT_LANGUAGE:
            indexer_api_params["language"] = indexer_lang

        if show.dvd_order != 0:
            indexer_api_params["dvdorder"] = True

        if season is None and episode is None:
            return show.indexer_api

        return show.indexer_api[show.indexerid][season][episode]
    except (
        IndexerEpisodeNotFound,
        IndexerSeasonNotFound,
        IndexerShowNotFound,
    ) as error:
        log.debug("Unable to validate show. Reason: {0!r}", error.message)
        pass