Skip to content

Commit

Permalink
Enhancement/improve-error-messaging-for-role-forbidden (#5554)
Browse files Browse the repository at this point in the history
# Description
<!-- Please include a summary of the changes and the related issue.
Please also include relevant motivation and context. List any
dependencies that are required for this change. -->

Closes #<issue_number>

**Type of change**
<!-- Please delete options that are not relevant. Remember to title the
PR according to the type of change -->

- Bug fix (non-breaking change which fixes an issue)
- New feature (non-breaking change which adds functionality)
- Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- Refactor (change restructuring the codebase without changing
functionality)
- Improvement (change adding some improvement to an existing
functionality)
- Documentation update

**How Has This Been Tested**
<!-- Please add some reference about how your feature has been tested.
-->

**Checklist**
<!-- Please go over the list and make sure you've taken everything into
account -->

- I added relevant documentation
- I followed the style guidelines of this project
- I did a self-review of my code
- I made corresponding changes to the documentation
- I confirm My changes generate no new warnings
- I have added tests that prove my fix is effective or that my feature
works
- I have added relevant notes to the CHANGELOG.md file (See
https://keepachangelog.com/)

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Paco Aranda <[email protected]>
  • Loading branch information
3 people authored Oct 2, 2024
1 parent 84de20c commit f41b643
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion argilla/src/argilla/_exceptions/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class BadRequestError(ArgillaAPIError):


class ForbiddenError(ArgillaAPIError):
message = "Forbidden request to the server"
message = "User role is forbidden from performing this action by server"


class NotFoundError(ArgillaAPIError):
Expand Down
21 changes: 19 additions & 2 deletions argilla/src/argilla/datasets/_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,13 @@
from typing import Optional, Union
from uuid import UUID, uuid4

try:
from typing import Self
except ImportError:
from typing_extensions import Self

from argilla._api import DatasetsAPI
from argilla._exceptions import NotFoundError, SettingsError
from argilla._exceptions import NotFoundError, SettingsError, ForbiddenError
from argilla._models import DatasetModel
from argilla._resource import Resource
from argilla.client import Argilla
Expand Down Expand Up @@ -157,7 +162,16 @@ def create(self) -> "Dataset":
Returns:
Dataset: The created dataset object.
"""
super().create()
try:
super().create()
except ForbiddenError as e:
settings_url = f"{self._client.api_url}/user-settings"
user_role = self._client.me.role.value
user_name = self._client.me.username
workspace_name = self.workspace.name
message = f"""User '{user_name}' is not authorized to create a dataset in workspace '{workspace_name}'
with role '{user_role}'. Go to {settings_url} to view your role."""
raise ForbiddenError(message) from e
try:
return self._publish()
except Exception as e:
Expand Down Expand Up @@ -277,3 +291,6 @@ def _sanitize_name(cls, name: str):
for character in ["/", "\\", ".", ",", ";", ":", "-", "+", "="]:
name = name.replace(character, "-")
return name

def _with_client(self, client: Argilla) -> "Self":
return super()._with_client(client=client)

0 comments on commit f41b643

Please sign in to comment.