mpruvot / python_chess_app

0 stars 0 forks source link

raise for status before check #15

Closed pbrochar closed 6 months ago

pbrochar commented 6 months ago

https://github.com/mpruvot/python_chess_app/blob/9a22b93faca5e7b7fc8a8d75bca898c75c7f34fe/services/strapi_service.py#L116

Something like:

        try:
            response = requests.get(f"{self.API_URL}/games/{game_id}")
            response.raise_for_status()
        except requests.exceptions.HTTPError as err:
            if err.status_code == 404:
                raise GameNotFoundError(f"No game with ID {game_id} found")
            raise
        else: #not mandatory
            game_json = response.json()["data"]
            return self._convert_json_to_game_object(game_json)