Skip to content

Commit

Permalink
Merge pull request #46 from rogers-obrien-rad/hotfix/no-ref/updated_e…
Browse files Browse the repository at this point in the history
…rrors

bugfix: check for 403 status on create
  • Loading branch information
HagenFritz committed Aug 30, 2023
2 parents bf880a0 + 38bfcf0 commit d570650
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
16 changes: 11 additions & 5 deletions propycore/access/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from fuzzywuzzy import fuzz

from propycore.exceptions import NotFoundItemError, WrongParamsError, ProcoreException
from propycore.exceptions import NotFoundItemError, WrongParamsError, ProcoreException, NoPrivilegeError

class Documents(Base):
"""
Expand Down Expand Up @@ -299,8 +299,11 @@ def create(self, company_id, project_id, folder_name, folder_id=None):
additional_headers=headers,
data=data
)
except ProcoreException:
raise WrongParamsError(f"Folder {folder_name} already exists")
except ProcoreException as e:
if "403" in e:
raise NoPrivilegeError(f"Data connection app or permission template does not allow creation of folders")
else:
raise WrongParamsError(f"Folder {folder_name} already exists")

return doc_info

Expand Down Expand Up @@ -454,8 +457,11 @@ def create(self, company_id, project_id, filepath, folder_id=None, description=N
data=data,
files=file
)
except ProcoreException:
raise WrongParamsError(f"File {filename} already exists")
except ProcoreException as e:
if "403" in e:
raise NoPrivilegeError(f"Data connection app or permission template does not allow creation of files")
else:
raise WrongParamsError(f"File {filename} already exists")

return doc_info

Expand Down
7 changes: 5 additions & 2 deletions propycore/access/generic_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pathlib
sys.path.append(f"{pathlib.Path(__file__).resolve().parent.parent}")

from propycore.exceptions import NotFoundItemError
from propycore.exceptions import NotFoundItemError, NoPrivilegeError, WrongParamsError

from exceptions import *

Expand Down Expand Up @@ -161,7 +161,10 @@ def create_tool_item(self, company_id, project_id, tool_id, data):
data=data
)
except ProcoreException as e:
raise WrongParamsError(e)
if "403" in e:
raise NoPrivilegeError(f"Data connection app or permission template does not allow creation of generic tools")
else:
raise WrongParamsError(e)

return item_info

Expand Down

0 comments on commit d570650

Please sign in to comment.