Skip to content
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,14 @@ The following functions are possible
- Link an available other projects to each specific project
- Override the project information
- Override the component information
- Add affiliated institutions to the created project/component and to the forked project

The impossible ones:
- Update attributes for available projects

**\* Notice** about the order of creating a project/component:
- Create project (includes `category`, `title`, `description`, `public`, `tags`)
- Add affiliated institutions to the created project/component
- Add license (as `node_license`)
- Create components for the created project
- Link to other projects (as `project_links`)
Expand Down
2 changes: 1 addition & 1 deletion grdmcli/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,5 +171,5 @@ def main():
cli_parser.parse_args(_args)


if __name__ == '__main__':
if __name__ == '__main__': # pragma: no cover
main()
4 changes: 0 additions & 4 deletions grdmcli/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@
PAGE_SIZE_SERVER = 100
MAX_THREADS_CALL_API = 10

# Maximum data return from API
# (update it if the max range of return data per_page of server is change)
MAX_THREADS_CALL_API = 10

MAX_PAGE_SIZE = 1000
PAGE_SIZE_QUERY_PARAM = 'page[size]'
ORDERING_QUERY_PARAM = 'sort'
Expand Down
3 changes: 3 additions & 0 deletions grdmcli/grdm_client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def __init__(self, **kwargs):

from .users import (
_users_me,
_users_institutions,
)
# For projects functions
from .licenses import (
Expand All @@ -34,6 +35,8 @@ def __init__(self, **kwargs):
_load_project,
_fork_project,
_create_project,
_prepare_institutions_relationship_data,
_add_node_institutions,
_link_project_to_project,
_add_project_pointers,
_add_project_components,
Expand Down
15 changes: 14 additions & 1 deletion grdmcli/grdm_client/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def __init__(self, **kwargs):

self.user = None
self.is_authenticated = False
self.affiliated_institutions = []

# Call initial methods before parse_args
self._load_option_from_config_file()
Expand Down Expand Up @@ -116,9 +117,21 @@ def _request(self, method, url, params=None, data=None, headers=None):
error_msg = error.detail
if hasattr(error, 'source'):
error_msg = f'{error_msg}. The pointer is {error.source.pointer}'
except Exception:
except Exception as ex:
error_msg = f'{_response.status_code} {_response.reason}'

# Keep parse context for troubleshooting unexpected API responses.
response_content = _response.content
if isinstance(response_content, (bytes, bytearray)):
response_content = response_content.decode('utf-8', errors='replace')
else:
response_content = str(response_content)
error_msg = (
f'{error_msg}.'
f'\n - Failed to parse API error response: {type(ex).__name__}: {ex}'
f'\n - Response content: {response_content}'
)

return None, error_msg

return _response, None
Expand Down
Loading