Skip to content

Commit c249d67

Browse files
committed
fixed raise error syntax'
1 parent 6fc0dc9 commit c249d67

7 files changed

+40
-20
lines changed

sdk/Table/azure/storage/tables/_table_service_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def delete_table(self, table_name):
7878
response = self._client.table.delete(table=table_name)
7979
return response
8080

81-
def query_table_entities(self, table_name):
81+
def query_table(self, table_name):
8282
response = self._client.table.query_entities(table_name=table_name)
8383
return response
8484

sdk/Table/samples/CreateQuery.py

Lines changed: 0 additions & 8 deletions
This file was deleted.

sdk/Table/samples/create_batch.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class CreateBatch(object):
2+
def build_batch_operations(self):
3+
from azure.storage.tables import TableServiceClient

sdk/Table/samples/create_query.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class CreateODataQuery(object):
2+
3+
def creating_odata_query_entities(self):
4+
5+
from azure.storage.tables import TableServiceClient
6+
from azure.storage.tables._generated.operations._service_operations import HttpResponseError
7+
8+
table_client = TableServiceClient(account_url=self.account_url, credential=self.account_key)
9+
try:
10+
queried_table = table_client.query_table_entities(table_name=self.table_name,partition_key=self.partition_key,row_key=self.row_key)
11+
print(queried_table.table_name)
12+
except HttpResponseError as e:
13+
print(e.message)

sdk/Table/samples/creation_deletion_of_table.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,32 @@ class CreateDeleteTable(object):
1616
def create_table(self):
1717
from azure.storage.tables import TableServiceClient
1818
from azure.storage.tables._generated.operations._service_operations import HttpResponseError
19+
from azure.storage.tables._generated.operations._service_operations import ResourceExistsError
1920
table_client = TableServiceClient(account_url=self.account_url, credential=self.access_key)
21+
22+
# add in existing table error handling
2023
try:
2124
table_created = table_client.create_table(table_name=self.table_name)
2225
print(table_created.table_name)
2326
return table_created.table_name
24-
except HttpResponseError as e:
25-
print(e.message)
27+
except HttpResponseError and ResourceExistsError:
28+
raise ResourceExistsError
29+
print(HttpResponseError.response)
2630

2731
def delete_table(self):
2832
from azure.storage.tables import TableServiceClient
2933
from azure.storage.tables._generated.operations._service_operations import HttpResponseError
34+
from azure.storage.tables._generated.operations._service_operations import ResourceNotFoundError
3035
table_client = TableServiceClient(account_url=self.account_url, credential=self.access_key)
36+
37+
#check table is there to delete
3138
try:
3239
table_deleted = table_client.delete_table(table_name=self.table_name)
3340
print(table_deleted)
3441
return table_deleted
35-
except HttpResponseError as e:
36-
print(e.message)
42+
except HttpResponseError and ResourceNotFoundError:
43+
raise ResourceNotFoundError
44+
print (HttpResponseError.response)
3745

3846

3947
if __name__ == '__main__':

sdk/Table/samples/inserting_deleting_entities.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@ def insert_entity(self):
2121

2222
from azure.storage.tables import TableServiceClient
2323
from azure.storage.tables._generated.operations._service_operations import HttpResponseError
24+
from azure.storage.tables._generated.operations._service_operations import ResourceExistsError
2425
table_client = TableServiceClient(account_url=self.account_url,credential=self.credential)
2526
try:
2627
inserted_entity = table_client.insert_entity(table_name=self.table_name)
27-
except HttpResponseError as e:
28-
print(e.response)
29-
return inserted_entity
28+
print(inserted_entity)
29+
except HttpResponseError and ResourceExistsError:
30+
raise ResourceExistsError
31+
print(HttpResponseError.response)
3032

3133
def delete_entity(self):
3234
"""Deletes the specified entity in a table.
@@ -49,9 +51,11 @@ def delete_entity(self):
4951

5052
from azure.storage.tables import TableServiceClient
5153
from azure.storage.tables._generated.operations._service_operations import HttpResponseError
54+
from azure.storage.tables._generated.operations._service_operations import ResourceNotFoundError
5255
table_client = TableServiceClient(account_url=self.account_url, credential=self.credential)
5356
try:
5457
deleted_entity = table_client.delete_entity(table_name=self.table_name)
55-
except HttpResponseError as e:
56-
print(e.response)
57-
return deleted_entity
58+
print(deleted_entity)
59+
except HttpResponseError and ResourceNotFoundError:
60+
raise ResourceNotFoundError
61+
print(HttpResponseError.response)

sdk/Table/samples/querying_table.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ class QueryTable(object):
33
def queryTable(self):
44
from azure.storage.tables import TableServiceClient
55
table_client = TableServiceClient(account_url=self.account_url, credential=self.credential)
6-
queried_table = table_client.query_table_entities(table_name=self.table_name)
6+
queried_table = table_client.query_table(table_name=self.table_name)
77
print(queried_table.table_name)
88

99

0 commit comments

Comments
 (0)