Class: CMIS::Connection::ResponseParser

Inherits:
Faraday::Middleware
  • Object
show all
Defined in:
lib/cmis/connection/response_parser.rb

Constant Summary collapse

JSON_CONTENT_TYPE =
/\/(x-)?json(;.+?)?$/i.freeze

Instance Method Summary collapse

Instance Method Details

#call(env) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/cmis/connection/response_parser.rb', line 9

def call(env)
  @app.call(env).on_complete do |env|
    case env[:status]
    when 401
      raise Exceptions::Unauthorized
    else
      if env[:response_headers][:content_type] =~ JSON_CONTENT_TYPE
        env[:body] = JSON.parse(env[:body])
        check_for_cmis_exception!(env[:body])
      end
    end
  end
end