Skip to content

Commit

Permalink
Merge pull request #51 from AbelHu/master
Browse files Browse the repository at this point in the history
Log more information when an exception occurs in table_service
  • Loading branch information
vinjiang authored Sep 30, 2016
2 parents dd12a5c + c3aa4de commit bf84124
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/azure/storage/service/serialization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ def slopify(xml)
end

def expect_node(node_name, xml)
raise "Xml is not a #{node_name} node." unless xml.name == node_name
raise "Xml is not a #{node_name} node. xml:\n#{xml}" unless xml.name == node_name
end
end

Expand Down
22 changes: 22 additions & 0 deletions lib/azure/storage/table/table_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ def get_table(table_name, options={})
response = call(:get, table_uri(table_name, query))
results = Table::Serialization.hash_from_entry_xml(response.body)
results[:updated]
rescue => e
raise_with_response(e, response)
end

# Public: Gets a list of all tables on the account.
Expand Down Expand Up @@ -136,6 +138,8 @@ def query_tables(options={})
values = Azure::Service::EnumerationResults.new(entries)
values.continuation_token = response.headers["x-ms-continuation-NextTableName"]
values
rescue => e
raise_with_response(e, response)
end

# Public: Gets the access control list (ACL) for the table.
Expand All @@ -162,6 +166,8 @@ def get_table_acl(table_name, options={})
signed_identifiers = []
signed_identifiers = Table::Serialization.signed_identifiers_from_xml response.body unless response.body == nil or response.body.length < 1
signed_identifiers
rescue => e
raise_with_response(e, response)
end

# Public: Sets the access control list (ACL) for the table.
Expand Down Expand Up @@ -225,6 +231,8 @@ def insert_entity(table_name, entity_values, options={})
entity.etag = response.headers['etag'] || result[:etag]
entity.properties = result[:properties]
end
rescue => e
raise_with_response(e, response)
end

# Public: Queries entities for the given table name
Expand Down Expand Up @@ -281,6 +289,8 @@ def query_entities(table_name, options={})
} if response.headers["x-ms-continuation-NextPartitionKey"]

entities
rescue => e
raise_with_response(e, response)
end

# Public: Updates an existing entity in a table. The Update Entity operation replaces
Expand Down Expand Up @@ -321,6 +331,8 @@ def update_entity(table_name, entity_values, options={})

response = call(:put, uri, body, headers)
response.headers["etag"]
rescue => e
raise_with_response(e, response)
end

# Public: Updates an existing entity by updating the entity's properties. This operation
Expand Down Expand Up @@ -361,6 +373,8 @@ def merge_entity(table_name, entity_values, options={})

response = call(:post, uri, body, headers)
response.headers["etag"]
rescue => e
raise_with_response(e, response)
end

# Public: Inserts or updates an existing entity within a table by merging new property values into the entity.
Expand Down Expand Up @@ -462,6 +476,8 @@ def execute_batch(batch, options={})
body = batch.to_body
response = call(:post, generate_uri('/$batch', query), body, headers)
batch.parse_response(response)
rescue => e
raise_with_response(e, response)
end

# Public: Gets an existing entity in the table.
Expand Down Expand Up @@ -568,6 +584,12 @@ def encodeODataUriValue(value)

value
end

protected
def raise_with_response(e, response)
raise e if response.nil?
raise "Response header: #{response.headers.inspect}\nResponse body: #{response.body.inspect}\n#{e.inspect}\n#{e.backtrace.join("\n")}"
end
end
end
end
Expand Down

0 comments on commit bf84124

Please sign in to comment.