Skip to content

Commit

Permalink
Add more exception handling to HTTPCameraAgent (#746)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidvng authored Sep 3, 2024
1 parent 3c8e2a6 commit dd9cc2a
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions socs/agents/http_camera/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def acq(self, session, params=None):
"password": camera['password']}}}]
try:
resp = requests.post(login_url, data=json.dumps(login_payload), verify=False)
except (requests.exceptions.RequestException, ReadTimeoutError) as e:
except (requests.exceptions.ConnectionError, requests.exceptions.RequestException, ReadTimeoutError) as e:
self.log.error(f'{e}')
self.log.info("Unable to get response from camera.")
data[camera['location']]['last_attempt'] = time.time()
Expand Down Expand Up @@ -157,7 +157,7 @@ def acq(self, session, params=None):
response = requests.get(url, params=payload, stream=True, timeout=5, verify=False)
elif camera['brand'] == 'acti':
response = requests.get(url, params=payload, stream=True, timeout=5)
except (requests.exceptions.RequestException, ReadTimeoutError) as e:
except (requests.exceptions.ConnectionError, requests.exceptions.RequestException, ReadTimeoutError) as e:
self.log.error(f'{e}')
self.log.info("Unable to get response from camera.")
data[camera['location']]['last_attempt'] = time.time()
Expand All @@ -174,12 +174,18 @@ def acq(self, session, params=None):
out_file.flush()
os.fsync(out_file.fileno())
self.log.debug(f"Wrote {ctime}.jpg to /{camera['location']}/{ctime_dir}.")
except ReadTimeoutError as e:
except (requests.exceptions.ConnectionError, requests.exceptions.RequestException, ReadTimeoutError) as e:
self.log.error(f'{e}')
self.log.info("Timeout occurred while writing to file.")
data[camera['location']]['last_attempt'] = time.time()
data[camera['location']]['connected'] = False
continue
except Exception as e:
self.log.error(f'{e}')
self.log.info("Unexpected error occurred while writing to file.")
data[camera['location']]['last_attempt'] = time.time()
data[camera['location']]['connected'] = False
continue
finally:
response.close()
shutil.copy2(filename, latest_filename)
Expand Down

0 comments on commit dd9cc2a

Please sign in to comment.