Skip to content

Commit

Permalink
Except requests.exceptions.HTTPError
Browse files Browse the repository at this point in the history
  • Loading branch information
hagenw committed Sep 28, 2021
1 parent 0721557 commit 24cf0e9
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions audbackend/core/artifactory.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import requests
import typing

import audfactory
Expand Down Expand Up @@ -53,9 +54,12 @@ def _exists(
) -> bool:
r"""Check if file exists on backend."""
try:
# Can lead to RuntimeError: 404 page not found
# Can lead to
# RuntimeError: 404 page not found
# or
# requests.exceptions.HTTPError: 403 Client Error
return audfactory.path(path).exists()
except RuntimeError: # pragma: nocover
except self._non_existing_path_error: # pragma: nocover
return False

def _get_file(
Expand Down Expand Up @@ -84,7 +88,7 @@ def _glob(
path = audfactory.path(url)
try:
result = [str(x) for x in path.glob(pattern)]
except RuntimeError: # pragma: no cover
except self._non_existing_path_error: # pragma: nocover
result = []
return result

Expand Down Expand Up @@ -123,3 +127,18 @@ def _versions(
r"""Versions of a file."""
group_id = audfactory.path_to_group_id(folder)
return audfactory.versions(self.host, self.repository, group_id, name)

_non_existing_path_error = (RuntimeError, requests.exceptions.HTTPError)
r"""Error expected for non-existing paths.
If a user has no permission to a given path
or the path does not exists :func:`audfactory.path`
might return a
``RuntimeError: 404 page not found``
or
``requests.exceptions.HTTPError: 403 Client Error``
error,
which might depend on the instaleld ``dohq-artifactory``
version. So we better catch both of them.
"""

0 comments on commit 24cf0e9

Please sign in to comment.