From b356689f26f380c38dcec828fd256d17b86ec849 Mon Sep 17 00:00:00 2001 From: saadmk11 Date: Sat, 13 Apr 2019 22:07:18 +0600 Subject: [PATCH] Handle more errors when setting up webhooks --- readthedocs/oauth/services/bitbucket.py | 9 +++++++++ readthedocs/oauth/services/gitlab.py | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/readthedocs/oauth/services/bitbucket.py b/readthedocs/oauth/services/bitbucket.py index 6a308f5d0a0..d4093bbe044 100644 --- a/readthedocs/oauth/services/bitbucket.py +++ b/readthedocs/oauth/services/bitbucket.py @@ -239,6 +239,15 @@ def setup_webhook(self, project): project, ) return (True, resp) + + if resp.status_code in [401, 403, 404]: + log.info( + 'Bitbucket project does not exist or user does not have ' + 'permissions: project=%s', + project, + ) + return (False, resp) + # Catch exceptions with request or deserializing JSON except (RequestException, ValueError): log.exception( diff --git a/readthedocs/oauth/services/gitlab.py b/readthedocs/oauth/services/gitlab.py index dfc82aced12..19e01ab7b1e 100644 --- a/readthedocs/oauth/services/gitlab.py +++ b/readthedocs/oauth/services/gitlab.py @@ -301,6 +301,15 @@ def setup_webhook(self, project): project, ) return (True, resp) + + if resp.status_code in [401, 403, 404]: + log.info( + 'Gitlab project does not exist or user does not have ' + 'permissions: project=%s', + project, + ) + return (False, resp) + except (RequestException, ValueError): log.exception( 'GitLab webhook creation failed for project: %s',