module OMCMS class ParseResponse < Faraday::Middleware def initialize(app) super app @app = app end 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)