lib/fun_translations/request.rb in fun_translations-0.0.1.rc1 vs lib/fun_translations/request.rb in fun_translations-0.0.1

- old
+ new

@@ -18,18 +18,19 @@ private # Parses response body using JSON # or raises an error if the status code is not 2xx def respond_with(response) - body = response.body.empty? ? response.body : JSON.parse(response.body) + raw_body = response.body + body = raw_body.empty? ? raw_body : JSON.parse(raw_body) respond_with_error(response.status, body['error']) if body.key?('error') || !response.success? body['contents'] end def respond_with_error(code, body) - raise(FunTranslations::Error, body) unless FunTranslations::Error::ERRORS.key? code + raise(FunTranslations::Error.from_response(body)) unless FunTranslations::Error::ERRORS.key? code raise FunTranslations::Error::ERRORS[code].from_response(body) end end end