Permalink
Browse files

Revised error handling

  • Loading branch information...
1 parent 237f259 commit 77800a1d912c0cee078136d18fcb50765c1a7f92 @visoft committed Jul 21, 2013
Showing with 21 additions and 6 deletions.
  1. +5 −0 CHANGELOG.md
  2. +1 −2 features/error_handling.feature
  3. +6 −1 lib/ruby_odata/exceptions.rb
  4. +1 −1 lib/ruby_odata/service.rb
  5. +8 −2 spec/service_spec.rb
View
@@ -136,3 +136,8 @@
* Updated the [VCR](https://github.com/myronmarston/vcr) and [WebMock](https://github.com/bblimke/webmock) gems to the latest versions (used for testing)
* Specified activesupport ~> 3.0 (in gemfiles/ruby187) for Ruby 1.8.7 as activesupport 4 doesn't support Ruby < 1.9.3
+## 0.1.5
+* **BREAKING CHANGES**
+ * Previously if the OData service threw an exception, ruby_odata threw a generic error with the message that would start with "HTTP Error XXX: ". Instead of the message, the Error that is thrown is an `OData::ServiceError`. It has an `http_code` property on it, thus, the message is now just the text from the OData error without the "HTTP Error XXX: " prefix. This could potentially cause you problems if you were sniffing error messages for the HTTP error code.
+
+* Added the ability to query the OData service using the [$select system query option](http://www.odata.org/documentation/odata-v2-documentation/uri-conventions/#48_Select_System_Query_Option_select)
@@ -10,5 +10,4 @@ Background:
Scenario: Violate a data type conversion (empty string to decimal)
Given I call "AddToProducts" on the service with a new "Product" object with Price: ""
- When I save changes it should throw an exception with message containing "HTTP Error 400"
-
+ When I save changes it should throw an exception with message containing "Error encountered in converting the value"
@@ -2,5 +2,10 @@ module OData
# Raised when a user attempts to do something that is not supported
class NotSupportedError < StandardError; end
# Raised when the service returns an error
- class ServiceError < StandardError; end
+ class ServiceError < StandardError
+ attr_reader :http_code
+ def initialize(code)
+ @http_code = code
+ end
+ end
end
@@ -323,7 +323,7 @@ def handle_exception(e)
error = Nokogiri::XML(e.response)
message = error.xpath("m:error/m:message", @ds_namespaces).first.content
- raise ServiceError, "HTTP Error #{code}: #{message}"
+ raise ServiceError.new(code), message
end
# Loops through the standard properties (non-navigation) for a given class and returns the appropriate list of methods
View
@@ -944,7 +944,10 @@ module OData
it "raises an exception" do
svc = OData::Service.new "http://test.com/test.svc/"
svc.Categories.select "Price"
- lambda { svc.execute }.should raise_error(OData::ServiceError, "HTTP Error 400: Type 'RubyODataService.Category' does not have a property named 'Price' or there is no type with 'Price' name.")
+ expect { svc.execute }.to raise_error(OData::ServiceError) { |error|
+ error.http_code.should eq 400
+ error.message.should eq "Type 'RubyODataService.Category' does not have a property named 'Price' or there is no type with 'Price' name."
+ }
end
end
@@ -962,7 +965,10 @@ module OData
it "raises an exception" do
svc = OData::Service.new "http://test.com/test.svc/"
svc.Categories.select "Name,Products/Name"
- lambda { svc.execute }.should raise_error(OData::ServiceError, "HTTP Error 400: Only properties specified in $expand can be traversed in $select query options. Property .")
+ expect { svc.execute }.to raise_error(OData::ServiceError) { |error|
+ error.http_code.should eq 400
+ error.message.should eq "Only properties specified in $expand can be traversed in $select query options. Property ."
+ }
end
end
end

0 comments on commit 77800a1

Please sign in to comment.