Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not crash Syncsketch addon if it cannot connect to the Syncsketch server due to wrong server or credentials #9

Merged
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 28 additions & 5 deletions server/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,38 @@ async def create_syncsketch_webhook(self):
"Content-Type": "application/json",
}

existing_webhooks = requests.request(
"GET", syncsketch_endpoint, headers=headers)
try:
existing_webhooks = requests.request(
"GET", syncsketch_endpoint, headers=headers)
except requests.exceptions.ConnectionError:
# This could happen if the SyncSketch API is not reachable
# with e.g. authentication issues, or the server is down.
# Usually with a "Max retries exceeded with url" message.
logging.error(
f"SyncSketch API connection error at: {syncsketch_endpoint}")
return

if existing_webhooks.status_code == 404:
logging.error(
f"SyncSketch API is not reachable at: {syncsketch_endpoint}")
return

# In some cases the JSON response may not be retrievable and could
# end up with a JSONDecodeError if the response is not JSON.
try:
existing_webhooks_json = existing_webhooks.json()
except requests.exceptions.JSONDecodeError:
logging.error(
"Unable to decode JSON response from SyncSketch API: "
f"{existing_webhooks}")
return

if existing_webhooks.status_code == 400:
logging.error(existing_webhooks.json())
logging.error(existing_webhooks_json)
return

if existing_webhooks.json():
for webhook in existing_webhooks.json():
if existing_webhooks_json:
for webhook in existing_webhooks_json:
if (
webhook.get("url") == ayon_endpoint
and webhook.get("type") == "all"
Expand Down