Skip to content

Commit

Permalink
fix: properly return and handle errors
Browse files Browse the repository at this point in the history
  • Loading branch information
vile committed May 28, 2024
1 parent 5b28f4a commit e65e646
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
24 changes: 15 additions & 9 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,13 @@ def run(config: dict) -> None:

if config["scrape_permission_info"]:
guild_roles: list = guild.scrape_guild_roles(token, server_id)
guild_formatted: str = display.build_permissions_table(
guild_roles, config["permissions_to_scrape"]
)
print(f"{guild_formatted}\n")
if len(guild_roles) == 0:
print(f"{Fore.RED}[!] There was an error getting guild roles{Fore.RESET}") # fmt: skip
else:
guild_formatted: str = display.build_permissions_table(
guild_roles, config["permissions_to_scrape"]
)
print(f"{guild_formatted}\n")

if config["export_results"]:
export.export_scrape_to_file(guild_formatted, server_id, "roles")
Expand All @@ -109,11 +112,14 @@ def run(config: dict) -> None:
if type(value) is int
}
channels: list = guild.get_channels(token, server_id)
channel_overwrites: str = overwrites.parse_permissions(
channels,
int_only_permissions,
)
print(f"{channel_overwrites}\n")
if "error" in channels:
print(f"{Fore.RED}[!] There was an error getting guild channels: {channels['error']}{Fore.RESET}") # fmt: skip
else:
channel_overwrites: str = overwrites.parse_permissions(
channels,
int_only_permissions,
)
print(f"{channel_overwrites}\n")

if config["export_results"]:
export.export_scrape_to_file(guild_formatted, server_id, "overwrites")
Expand Down
4 changes: 2 additions & 2 deletions utils/guild.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ def scrape_guild_roles(token: str, server_id: int) -> list:
if r.status_code == 200:
return r.json()
raise Exception(f"Bad HTTP code when scraping guild roles, {r.status_code}")
except Exception as error:
return {"error": error}
except Exception:
return []


def get_channels(token: str, server_id: int) -> dict:
Expand Down

0 comments on commit e65e646

Please sign in to comment.