better error handling
This commit is contained in:
parent
599c66f436
commit
f703768161
@ -40,11 +40,24 @@ def main() -> int:
|
|||||||
|
|
||||||
# Continuously fetch the pwnagotchi screen
|
# Continuously fetch the pwnagotchi screen
|
||||||
while True:
|
while True:
|
||||||
|
|
||||||
|
# If the window is closed, exit
|
||||||
|
for event in pygame.event.get():
|
||||||
|
if event.type == pygame.QUIT:
|
||||||
|
return 0
|
||||||
|
|
||||||
|
# Attempt to fetch the pwnagotchi screen
|
||||||
try:
|
try:
|
||||||
# Fetch the pwnagotchi screen
|
# Fetch the pwnagotchi screen
|
||||||
logger.debug(f"Fetching pwnagotchi screen from {args.host}:{args.port}")
|
logger.debug(f"Fetching pwnagotchi screen from {args.host}:{args.port}")
|
||||||
response = requests.get(f"http://{args.host}:{args.port}/ui", auth=(args.username, args.password))
|
try:
|
||||||
response.raise_for_status()
|
response = requests.get(f"http://{args.host}:{args.port}/ui", auth=(args.username, args.password), timeout=1)
|
||||||
|
response.raise_for_status()
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Failed to connect to pwnagotchi at {args.host}:{args.port}")
|
||||||
|
logger.error(f"Error: {e}")
|
||||||
|
time.sleep(args.refresh_rate)
|
||||||
|
continue
|
||||||
screen_data = response.content
|
screen_data = response.content
|
||||||
|
|
||||||
# Draw the screen to the window
|
# Draw the screen to the window
|
||||||
@ -64,10 +77,6 @@ def main() -> int:
|
|||||||
|
|
||||||
time.sleep(args.refresh_rate)
|
time.sleep(args.refresh_rate)
|
||||||
|
|
||||||
# If the window is closed, exit
|
|
||||||
for event in pygame.event.get():
|
|
||||||
if event.type == pygame.QUIT:
|
|
||||||
return 0
|
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user