lib/omcms/middleware/parse_response.rb in omcms-ruby-client-1.1.0 vs lib/omcms/middleware/parse_response.rb in omcms-ruby-client-1.2.0

- old
+ new

@@ -1,19 +1,17 @@ module OMCMS class ParseResponse < Faraday::Middleware - def initialize app + def initialize(app) super app @app = app end - def on_complete response_env - if response_env.status >= 400 - return OMCMS::Response::Error.new(response_env) - else - return response_env.body - end - rescue => error - return OMCMS::Response::Error.new(error) + def on_complete(response_env) + return OMCMS::Response::Error.new(response_env) if response_env.status >= 400 + + response_env.body + rescue StandardError => e + OMCMS::Response::Error.new(e) end end end Faraday::Response.register_middleware(omcms_parse_response: OMCMS::ParseResponse)