diff --git a/onshape_robotics_toolkit/connect.py b/onshape_robotics_toolkit/connect.py index 5b1addf..26865cf 100644 --- a/onshape_robotics_toolkit/connect.py +++ b/onshape_robotics_toolkit/connect.py @@ -258,12 +258,20 @@ def get_elements(self, did: str, wtype: str, wid: str) -> dict[str, Element]: # /documents/d/{did}/{wvm}/{wvmid}/elements request_path = "/api/documents/d/" + did + "/" + wtype + "/" + wid + "/elements" - _elements_json = self.request( + response = self.request( HTTP.GET, request_path, - ).json() + ) + + if response.status_code == 404: + LOGGER.error(f"Elements not found for document: {did}") + return {} + + elif response.status_code == 403: + LOGGER.error(f"Access forbidden for document: {did}") + return {} - return {element["name"]: Element.model_validate(element) for element in _elements_json} + return {element["name"]: Element.model_validate(element) for element in response.json()} def get_variables(self, did: str, wid: str, eid: str) -> dict[str, Variable]: """ diff --git a/pyproject.toml b/pyproject.toml index 0e956ad..18024cf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,7 +2,7 @@ name = "onshape_robotics_toolkit" version = "0.0.1" description = "A python library to facilitate interaction with Onshape's REST API" -authors = ["Senthur Ayyappan "] +authors = ["Senthur Ayyappan "] repository = "https://github.com/neurobionics/onshape-robotics-toolkit" documentation = "https://neurobionics.github.io/onshape-robotics-toolkit/" readme = "README.md"