lib/wordnik/response.rb in wordnik-0.4.7 vs lib/wordnik/response.rb in wordnik-4.06.00

- old
+ new

@@ -23,12 +23,20 @@ # If body is JSON, parse it # TODO: If body is XML, parse it # Otherwise return raw string def body - JSON.parse raw.body#.encode(::Encoding::UTF_8, undef: :replace) - rescue - raw.body#.encode(::Encoding::UTF_8, undef: :replace) + + if self.code > 399 + raise AuthorizationError, raw.inspect + end + + begin + JSON.parse raw.body + rescue + raw.body + end + end def headers h = {} raw.headers_hash.each {|k,v| h[k] = v } \ No newline at end of file