meraki-analytics / cassiopeia

An all-inclusive Python framework for the Riot Games League of Legends API. Cass focuses on making the data easy and fun to work with, while providing all the tools necessary to create a website or do data analysis.
MIT License
553 stars 135 forks source link

How i can catch the exceptions #456

Open ahmedsafadii opened 4 months ago

ahmedsafadii commented 4 months ago

How i can catch the exceptions for example if the summoner is not found and I want to catch it so I can return a custom message.

def test():

lol_manager = LolManager()
puuid = "ovqw2cGBNvqhlGZV3u1lBWmROrfXVTnjjAfoOd5GN-e_YeTGnVossVzw84Z_GDHpvgDC_fVJ3FQACg1"
server = "EUW"
try:
    summoner = lol_manager.get_summoner_by_puuid(puuid=puuid, region=server)
    print("Summoner found:", summoner.account_id)
except HTTPError as e:
    print("HTTP error:", e)
except Exception as e:
    print("An unexpected error occurred:", e)

my settings

settings = {
            "RiotAPI": {
                "api_key": RIOT_API_KEY,
                "request_error_handling": {
                    "404": {"strategy": "throw"},
                    "429": {
                        "service": {
                            "strategy": "exponential_backoff",
                            "initial_backoff": 1.0,
                            "backoff_factor": 2.0,
                            "max_attempts": 4,
                        },
                        "method": {"strategy": "retry_from_headers", "max_attempts": 5},
                        "application": {
                            "strategy": "retry_from_headers",
                            "max_attempts": 5,
                        },
                    },
                    "500": {
                        "strategy": "exponential_backoff",
                        "initial_backoff": 1.0,
                        "backoff_factor": 2.0,
                        "max_attempts": 4,
                    },
                    "503": {
                        "strategy": "exponential_backoff",
                        "initial_backoff": 1.0,
                        "backoff_factor": 2.0,
                        "max_attempts": 8,
                    },
                    "timeout": {"strategy": "throw"},
                    "403": {"strategy": "throw"},
                    "504": {
                        "strategy": "exponential_backoff",
                        "initial_backoff": 1.0,
                        "backoff_factor": 2.0,
                        "max_attempts": 4,
                    },
                    "502": {
                        "strategy": "exponential_backoff",
                        "initial_backoff": 1.0,
                        "backoff_factor": 2.0,
                        "max_attempts": 4,
                    },
                },
            }
        }
machimozor commented 3 weeks ago

Hey, can you assign me this issue please !