Permalink
Browse files

raise an exception if the API call returns an error

  • Loading branch information...
1 parent 38826d5 commit 143fab1e9c4d77cb0f9c56042b6d536c3bf7ca61 @jimmycuadra jimmycuadra committed Dec 25, 2010
Showing with 8 additions and 0 deletions.
  1. +1 −0 lib/to_lang/connector.rb
  2. +7 −0 spec/to_lang/connector_spec.rb
View
@@ -13,6 +13,7 @@ def initialize(key)
def request(q, target, *args)
response = HTTParty.get request_url(q, target, *args)
+ raise response.parsed_response["error"]["message"] if response.parsed_response["error"] && response.parsed_response["error"]["message"]
response.parsed_response["data"]["translations"][0]["translatedText"]
end
@@ -47,5 +47,12 @@ def stub_bad_response(error_message)
end
end
end
+
+ context "with a bad language pair" do
+ it "raises an exception" do
+ stub_bad_response "Bad language pair: en|en"
+ expect { @connector.request("a pie", "en", :from => "en") }.to raise_error(RuntimeError, "Bad language pair: en|en")
+ end
+ end
end
end

0 comments on commit 143fab1

Please sign in to comment.