def api_error_handler(func):
    """Decorator to handle API errors from ResourceAPI methods
    and raise the appropriate exception.
    Args: func: the request method to decorate

    Example:
    ```python

    @api_error_handler
    def get(self, workspace_id: UUID) -> WorkspaceModel:
        ... # same code as before
    ```
    """

    def _error_switch(status_code: int, error_detail: str):
        switch = {
            400: BadRequestError,
            401: UnauthorizedError,
            403: ForbiddenError,
            404: NotFoundError,
            409: ConflictError,
            422: UnprocessableEntityError,
            500: InternalServerError,
        }
        exception_class = switch.get(status_code, ArgillaAPIError)
        raise exception_class(f"{exception_class.message}. Details: {error_detail}", status_code=status_code)

    def _handler_wrapper(*args, **kwargs):
        try:
            return func(*args, **kwargs)
        except HTTPStatusError as e:
            _error_switch(status_code=e.response.status_code, error_detail=e.response.text)

    return _handler_wrapper
Decorator to handle API errors from ResourceAPI methods
    and raise the appropriate exception.
    Args: func: the request method to decorate

    Example:
    ```python

    @api_error_handler
    def get(self, workspace_id: UUID) -> WorkspaceModel:
        ... # same code as before
    ```
    
argilla/src/argilla/_exceptions/_api.py