Class: OpenAI::MiddlewareErrors

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

Instance Method Summary collapse

Instance Method Details

#call(env) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/openai.rb', line 27

def call(env)
  @app.call(env)
rescue Faraday::Error => e
  raise e unless e.response.is_a?(Hash)

  logger = Logger.new($stdout)
  logger.formatter = proc do |_severity, _datetime, _progname, msg|
    "\033[31mOpenAI HTTP Error (spotted in ruby-openai #{VERSION}): #{msg}\n\033[0m"
  end
  logger.error(e.response[:body])

  raise e
end