class Appsignal::Rack::JSExceptionCatcher
@api private
@see docs.appsignal.com/front-end/error-handling.html<br><br>Sinatra::Application.use(Appsignal::Rack::JSExceptionCatcher)
@example with a Sinatra app
the error. It will return HTTP status code 202.
scenario this middleware still listens to the endpoint, but won’t record
still sends errors to this endpoint. When AppSignal is not active in this
JavaScript error catching turned on, we assume that a JavaScript script
If AppSignal is not active in the current environment, but does have
`frontend_error_catching_path` configuration option is active.
This is automatically included middleware in Rails apps if the
configuration option.
Listens to the endpoint specified in the ‘frontend_error_catching_path`
JavaScript error catching middleware.
def call(env)
def call(env) # Ignore other paths than the error catching path. return @app.call(env) unless error_cathing_endpoint?(env) # Prevent raising a 404 not found when a non-active environment posts # to this endpoint. unless Appsignal.active? return [ 202, {}, ["AppSignal JavaScript error catching endpoint is not active."] ] end begin body = JSON.parse(env["rack.input"].read) rescue JSON::ParserError return [400, {}, ["Request payload is not valid JSON."]] end if body["name"].is_a?(String) && !body["name"].empty? transaction = JSExceptionTransaction.new(body) transaction.complete! code = 200 else Appsignal.logger.debug \ "JSExceptionCatcher: Could not send exception, 'name' is empty." code = 422 end [code, {}, []] end
def error_cathing_endpoint?(env)
def error_cathing_endpoint?(env) env["PATH_INFO"] == Appsignal.config[:frontend_error_catching_path] end
def initialize(app, _options = nil)
def initialize(app, _options = nil) Appsignal.logger.debug \ "Initializing Appsignal::Rack::JSExceptionCatcher" @app = app end