Module: TemplateStreaming::ErrorRecovery::Helper

Includes:
Rendering
Defined in:
lib/template_streaming/error_recovery.rb

Instance Method Summary collapse

Methods included from Rendering

#uncaught_error_string, #uncaught_errors_html

Instance Method Details

#renderObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/template_streaming/error_recovery.rb', line 43

def render(*)
  begin
    super
  rescue ActionView::MissingTemplate => e
    # ActionView uses this as a signal to try another template engine.
    raise e
  rescue Exception => e
    raise e if !recover_from_errors?
    if HoptoadNotifier.configuration[:api_key]
      Rails.logger.error("#{e.class}: #{e.message}")
      Rails.logger.error(e.backtrace.join("\n").gsub(/^/, '  '))
      HoptoadNotifier.notify(e)
    end

    request.env[ENV_SHOW_DETAILS] = consider_all_requests_local || local_request?

    # TODO: Find a way to make this suck less.
    is_template_error = e.is_a?(ActionView::TemplateError)
    if is_template_error && e.file_name =~ %r'\Aapp/views/prelayouts/'
      # Error in prelayout - no head or body rendered yet.
      head = "<head><title>Rails Application Error</title></head>"
      body = "<body>#{uncaught_errors_html([e])}</body>"
      "<!DOCTYPE html><html>#{head}#{body}</html>"
    elsif is_template_error && e.file_name =~ %r'\Aapp/views/layouts/'
      # Error in layout - unclosed head tag has been rendered.
      head = "<title>Rails Application Error</title></head>"
      body = "<body>#{uncaught_errors_html([e])}</body>"
      "#{head}#{body}</html>"
    else
      # Body is being rendered - return nothing for this render
      # call, and render the exception in the middleware.
      request.env[ENV_EXCEPTIONS] << e
      ''
    end
  end
end