Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #48 from okgrow/master

Check that message is present before including it in the exception
  • Loading branch information...
commit 56c301e9c5511df447128cc3f193d7ce6abdb68d 2 parents e92c99c + 6b60b47
@visoft authored
View
6 lib/ruby_odata/service.rb
@@ -368,7 +368,11 @@ def handle_exception(e)
code = e.http_code
error = Nokogiri::XML(e.response)
- message = error.xpath("m:error/m:message", @ds_namespaces).first.content
+ message = if error.xpath("m:error/m:message", @ds_namespaces).first
+ error.xpath("m:error/m:message", @ds_namespaces).first.content
+ else
+ "Server returned error but no message."
+ end
raise ServiceError.new(code), message
end
View
5 spec/fixtures/error_without_message.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8" standalone="yes"?>
+<error
+ xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
+ <code></code>
+</error>
View
21 spec/service_spec.rb
@@ -121,6 +121,27 @@ module OData
end
end
+ describe "exception handling" do
+ before(:each) do
+ stub_request(:get, "http://test.com/test.svc/$metadata").
+ with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate'}).
+ to_return(:status => 200, :body => File.new(File.expand_path("../fixtures/sample_service/edmx_categories_products.xml", __FILE__)), :headers => {})
+
+ stub_request(:get, "http://test.com/test.svc/Categories?$select=Price").
+ with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate'}).
+ to_return(:status => 400, :body => File.new(File.expand_path("../fixtures/error_without_message.xml", __FILE__)), :headers => {})
+ end
+
+ it "includes a generic message if the error is not in the response" do
+ svc = OData::Service.new "http://test.com/test.svc/"
+ svc.Categories.select "Price"
+ expect { svc.execute }.to raise_error(OData::ServiceError) { |error|
+ error.http_code.should eq 400
+ error.message.should eq "Server returned error but no message."
+ }
+ end
+ end
+
describe "lowercase collections" do
before(:each) do
# Required for the build_classes method
Please sign in to comment.
Something went wrong with that request. Please try again.