Class: Logster::Middleware::Reporter
- Inherits:
-
Object
- Object
- Logster::Middleware::Reporter
- Defined in:
- lib/logster/middleware/reporter.rb
Constant Summary collapse
- PATH_INFO =
"PATH_INFO"
- SCRIPT_NAME =
"SCRIPT_NAME"
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, config = {}) ⇒ Reporter
constructor
A new instance of Reporter.
- #report_js_error(env) ⇒ Object
Constructor Details
Instance Method Details
#call(env) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/logster/middleware/reporter.rb', line 15 def call(env) Thread.current[Logster::Logger::LOGSTER_ENV] = env path = env[PATH_INFO] script_name = env[SCRIPT_NAME] if script_name && script_name.length > 0 path = script_name + path end if path == @error_path if !Logster.config.enable_js_error_reporting return [403, {}, "Access Denied"] end Logster.config.current_context.call(env) do if Logster.config.rate_limit_error_reporting req = Rack::Request.new(env) if Logster.store.rate_limited?(req.ip, perform: true) return [429, {}, "Rate Limited"] end end report_js_error(env) end return [200, {}, ["OK"]] end @app.call(env) ensure Thread.current[Logster::Logger::LOGSTER_ENV] = nil end |
#report_js_error(env) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/logster/middleware/reporter.rb', line 48 def report_js_error(env) req = Rack::Request.new(env) params = req.params = (params["message"] || "").dup << "\nUrl: " << params["url"] if params["url"] << "\nLine: " << params["line"] if params["line"] << "\nColumn: " << params["column"] if params["column"] << "\nWindow Location: " << params["window_location"] if params["window_location"] backtrace = params["stacktrace"] || "" Logster.store.report(::Logger::Severity::WARN, "javascript", , backtrace: backtrace, env: env) true end |