|
1 | 1 | from .endpoint import Endpoint
|
| 2 | +from .exceptions import EndpointUnavailableError, ServerResponseError |
2 | 3 | from .. import RequestFactory
|
3 | 4 | from ...models.tag_item import TagItem
|
4 | 5 | import logging
|
5 | 6 | import copy
|
6 | 7 |
|
7 |
| -logger = logging.getLogger('tableau.endpoint') |
| 8 | +logger = logging.getLogger('tableau.endpoint.resource_tagger') |
8 | 9 |
|
9 | 10 |
|
10 | 11 | class ResourceTagger(Endpoint):
|
11 | 12 | # Add new tags to resource
|
12 | 13 | def _add_tags(self, baseurl, resource_id, tag_set):
|
13 | 14 | url = "{0}/{1}/tags".format(baseurl, resource_id)
|
14 | 15 | add_req = RequestFactory.Tag.add_req(tag_set)
|
15 |
| - server_response = self.put_request(url, add_req) |
| 16 | + |
| 17 | + try: |
| 18 | + server_response = self.put_request(url, add_req) |
| 19 | + except ServerResponseError as e: |
| 20 | + if e.code == "404003": |
| 21 | + error = "Adding tags to this resource type is only available with REST API version 2.6 and later." |
| 22 | + raise EndpointUnavailableError(error) |
| 23 | + |
16 | 24 | return TagItem.from_response(server_response.content)
|
17 | 25 |
|
18 | 26 | # Delete a resource's tag by name
|
19 | 27 | def _delete_tag(self, baseurl, resource_id, tag_name):
|
20 | 28 | url = "{0}/{1}/tags/{2}".format(baseurl, resource_id, tag_name)
|
21 |
| - self.delete_request(url) |
| 29 | + |
| 30 | + try: |
| 31 | + self.delete_request(url) |
| 32 | + except ServerResponseError as e: |
| 33 | + if e.code == "404003": |
| 34 | + error = "Deleting tags from this resource type is only available with REST API version 2.6 and later." |
| 35 | + raise EndpointUnavailableError(error) |
22 | 36 |
|
23 | 37 | # Remove and add tags to match the resource item's tag set
|
24 | 38 | def _update_tags(self, baseurl, resource_item):
|
|
0 commit comments