lib/omcms/middleware/parse_response.rb in omcms-ruby-client-1.0.2 vs lib/omcms/middleware/parse_response.rb in omcms-ruby-client-1.0.3
- old
+ new
@@ -1,19 +1,20 @@
module OMCMS
- class ParseResponse
+ class ParseResponse < Faraday::Middleware
def initialize app
+ super app
@app = app
end
- def call request_env
- @app.call(request_env).on_complete do |response_env|
- if response_env.status >= 400
- return OMCMS::Response::Error.new(response_env)
- else
- return response_env.body
- 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)
end
end
end
+
+Faraday::Response.register_middleware(omcms_parse_response: OMCMS::ParseResponse)