module OMCMS class ParseResponse < Faraday::Middleware 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) end end end Faraday::Response.register_middleware(omcms_parse_response: OMCMS::ParseResponse)