Class: CMIS::ResponseParser

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

Instance Method Summary collapse

Instance Method Details

#call(env) ⇒ Object



134
135
136
137
138
139
140
141
142
143
144
# File 'lib/cmis/connection.rb', line 134

def call(env)
  @app.call(env).on_complete do |env|
    if env[:response_headers][:content_type] =~ /\/(x-)?json(;.+?)?$/
      env[:body] = JSON.parse(env[:body]).with_indifferent_access
      if env[:body].is_a?(Hash) && ex = env[:body][:exception]
        ruby_exception = "CMIS::Exceptions::#{ex.camelize}".constantize
        raise ruby_exception, env[:body]['message']
      end
    end
  end
end