lib/hanami/config.rb in hanami-2.0.3 vs lib/hanami/config.rb in hanami-2.1.0.beta1
- old
+ new
@@ -125,10 +125,62 @@
#
# @api public
# @since 2.0.0
setting :base_url, default: "http://0.0.0.0:2300", constructor: ->(url) { URI(url) }
+ # @!attribute [rw] render_errors
+ # Sets whether to catch exceptions and render error pages.
+ #
+ # For HTML responses, these error pages are in `public/{404,500}.html`.
+ #
+ # Defaults to `true` in production mode, `false` in all others.
+ #
+ # @return [Boolean]
+ #
+ # @api public
+ # @since 2.1.0
+ setting :render_errors, default: false
+
+ # @!attribute [rw] render_detailed_errors
+ # Sets whether to catch exceptions and render detailed, interactive error pages.
+ #
+ # Requires the hanami-webconsole gem to be available.
+ #
+ # Defaults to `false` in production mode, `true` in all others.
+ #
+ # @return [Boolean]
+ #
+ # @api public
+ # @since 2.1.0
+ setting :render_detailed_errors, default: false
+
+ # @!attribute [rw] render_error_responses
+ # Sets a mapping of exception class names (as strings) to symbolic response status codes used
+ # for rendering error responses.
+ #
+ # The response status codes will be passed to `Rack::Utils.status_code`.
+ #
+ # In ordinary usage, you should not replace this hash. Instead, add keys and values for the
+ # errors you want handled.
+ #
+ # @example
+ # config.render_error_responses
+ # # => {"Hanami::Router::NotFoundError" => :not_found}
+ #
+ # config.render_error_responses["MyNotFoundError"] = :not_found
+ #
+ # @return [Hash{String => Symbol}]
+ #
+ # @see #render_errors
+ #
+ # @api public
+ # @since 2.1.0
+ setting :render_error_responses, default: Hash.new(:internal_server_error).merge!(
+ "Hanami::Router::NotAllowedError" => :not_found,
+ "Hanami::Router::NotFoundError" => :not_found,
+ )
+
# Returns the app or slice's {Hanami::SliceName slice_name}.
#
# This is useful for default config values that depend on this name.
#
# @return [Hanami::SliceName]
@@ -215,9 +267,11 @@
@app_name = app_name
@env = env
# Apply default values that are only knowable at initialize-time (vs require-time)
self.root = Dir.pwd
+ self.render_errors = (env == :production)
+ self.render_detailed_errors = (env != :production)
load_from_env
@logger = Config::Logger.new(env: env, app_name: app_name)
# TODO: Make assets config dependent