Module: Bugsage::ExceptionHandler
- Defined in:
- lib/bugsage/exception_handler.rb
Class Method Summary collapse
- .bugsage_response?(body) ⇒ Boolean
- .extract(env, exception = nil) ⇒ Object
- .process(env, exception, render:) ⇒ Object
- .render_response(env, exception = nil) ⇒ Object
- .request_context(env) ⇒ Object
- .status_for(exception) ⇒ Object
- .store_exception(env, exception = nil) ⇒ Object
- .store_http_error(env, status, body) ⇒ Object
Class Method Details
.bugsage_response?(body) ⇒ Boolean
61 62 63 64 |
# File 'lib/bugsage/exception_handler.rb', line 61 def bugsage_response?(body) content = body.respond_to?(:join) ? body.join : body.to_s content.include?("BugSage caught") || content.include?("BugSage Dashboard") end |
.extract(env, exception = nil) ⇒ Object
7 8 9 |
# File 'lib/bugsage/exception_handler.rb', line 7 def extract(env, exception = nil) ExceptionSupport.extract(env, exception) end |
.process(env, exception, render:) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/bugsage/exception_handler.rb', line 27 def process(env, exception, render:) config = Bugsage.configuration return unless config.enabled? exception = extract(env, exception) return unless exception suggestion = Rule.match(exception) return unless suggestion context = request_context(env) ai_error = nil Store.add(suggestion, context, ai_error: ai_error, exception: exception) if config.capture_errors? ConsoleContext.set(exception: exception, context: context) if config.show_inline_console? AiContext.set(exception: exception, suggestion: suggestion, context: context) if config.ai_configured? return unless render && config.show_error_page? [status_for(exception), { "Content-Type" => "text/html" }, [ErrorPage.render(suggestion, context)]] end |
.render_response(env, exception = nil) ⇒ Object
11 12 13 |
# File 'lib/bugsage/exception_handler.rb', line 11 def render_response(env, exception = nil) process(env, exception, render: true) end |
.request_context(env) ⇒ Object
49 50 51 |
# File 'lib/bugsage/exception_handler.rb', line 49 def request_context(env) RequestContext.from_env(env) end |
.status_for(exception) ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/bugsage/exception_handler.rb', line 53 def status_for(exception) if ExceptionSupport.routing_error?(exception) || ExceptionSupport.record_not_found?(exception) 404 else 500 end end |
.store_exception(env, exception = nil) ⇒ Object
15 16 17 |
# File 'lib/bugsage/exception_handler.rb', line 15 def store_exception(env, exception = nil) process(env, exception, render: false) end |
.store_http_error(env, status, body) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/bugsage/exception_handler.rb', line 19 def store_http_error(env, status, body) config = Bugsage.configuration return unless config.enabled? && config.capture_http_errors? exception = HttpErrorCapture.build_exception(env, status, body) process(env, exception, render: false) end |