Class: Appsignal::Rack::JSExceptionCatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/appsignal/rack/js_exception_catcher.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ JSExceptionCatcher

Returns a new instance of JSExceptionCatcher.



4
5
6
7
# File 'lib/appsignal/rack/js_exception_catcher.rb', line 4

def initialize(app, options = {})
  Appsignal.logger.debug 'Initializing Appsignal::Rack::JSExceptionCatcher'
  @app, @options = app, options
end

Instance Method Details

#call(env) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/appsignal/rack/js_exception_catcher.rb', line 9

def call(env)
  if env['PATH_INFO'] == Appsignal.config[:frontend_error_catching_path]
    body = JSON.parse(env['rack.input'].read)

    if body['name'].is_a?(String) && body['name'].length > 0
      transaction = JSExceptionTransaction.new(body)
      transaction.complete!
      code = 200
    else
      Appsignal.logger.debug "JSExceptionCatcher: Could not send exception, 'name' is empty."
      code = 422
    end

    return [code, {}, []]
  else
    @app.call(env)
  end
end