Class: ChatGptErrorHandler::ErrorHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/chat_gpt_error_handler/error_handler.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ ErrorHandler

Returns a new instance of ErrorHandler.



6
7
8
9
10
11
12
13
# File 'lib/chat_gpt_error_handler/error_handler.rb', line 6

def initialize(app)
  @app = app
  if ChatGptErrorHandler.enabled
    OpenAI.configure do |config|
      config.access_token = ChatGptErrorHandler.openai_access_token || ENV.fetch('OPENAI_ACCESS_TOKEN')
    end
  end
end

Instance Method Details

#call(env) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/chat_gpt_error_handler/error_handler.rb', line 15

def call(env)
  begin
    @app.call(env)
  rescue => error
    send_to_gpt(error) if ChatGptErrorHandler.enabled
    raise error
  end
end