diff --git a/build.gradle b/build.gradle index a2871c0..6c0195a 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ plugins { } group 'no.datek' -version '0.18.2' +version '0.18.3' final String JRUBY_VERSION = '9.4.5.0'; repositories { diff --git a/src/main/resources/ruby/slim_helper.rb b/src/main/resources/ruby/slim_helper.rb index d6c56a9..efdb75b 100644 --- a/src/main/resources/ruby/slim_helper.rb +++ b/src/main/resources/ruby/slim_helper.rb @@ -25,10 +25,12 @@ def render(view_path, params = {}) view.render(model_map, request, response) response.body rescue Exception => e # rubocop: disable Lint/RescueException - LOG.error "Exception rendering partial template: #{view_path.inspect}" - LOG.error "#{e.class}: #{e.message}" - LOG.error e.to_s - LOG.info e.backtrace.join("\n") + if SlimRenderer.log_rendering_errors + LOG.error "Exception rendering partial template: #{view_path.inspect}" + LOG.error "#{e.class}: #{e.message}" + LOG.error e.to_s + LOG.info e.backtrace.join("\n") + end raise end diff --git a/src/main/resources/ruby/slim_renderer.rb b/src/main/resources/ruby/slim_renderer.rb index d42c34f..3642d6f 100644 --- a/src/main/resources/ruby/slim_renderer.rb +++ b/src/main/resources/ruby/slim_renderer.rb @@ -19,7 +19,6 @@ require_relative 'view_context' require_relative 'locale_helper' require_relative 'request_context' -require 'application_setup' module SlimRenderer extend LocaleHelper @@ -38,6 +37,16 @@ module SlimRenderer LAYOUT_TEMPLATE_PATH = "/views/layouts" DEFAULT_LAYOUT = "#{LAYOUT_TEMPLATE_PATH}/layout.slim" + @@log_rendering_errors = true + + def self.log_rendering_errors + @@log_rendering_errors + end + + def self.log_rendering_errors=(value) + @@log_rendering_errors = value + end + def self.render(template, model_map, rendering_context) request = RequestContextHolder.request_attributes.request locale = current_locale(request) @@ -98,7 +107,9 @@ def self.render(template, model_map, rendering_context) #{e.backtrace.join("\n")} HTML - LOG.error message + if log_rendering_errors + LOG.error message + end "

Whoops!

#{CGI.escapeHTML(message)}
" end @@ -126,3 +137,5 @@ def [](key) if (Java::JavaLang::System.getProperty("spring.profiles.active") || Java::JavaLang::System.getenv("SPRING_PROFILES_ACTIVE"))&.include?('development') require 'source_reloader' end + +require 'application_setup'