class StirFry::Pages::ErrorPage
ErrorPage is a custom component and main handler for server errors. It will respond with a specific mime type depending on what was requested.
Attributes
error is the error raised during the request cycle.
Public Class Methods
Source
# File lib/stir_fry/pages/error_page.rb, line 12 def initialize(error: "", **args) super @error = error end
Create a new error page that will display the message and status.
Calls superclass method
StirFry::Component::new
Public Instance Methods
Source
# File lib/stir_fry/pages/error_page.rb, line 32 def call if request.json? then response.json(render_json, status) elsif request.html? then response.html(render, status) else response.text(message, status) end end
Overrides Component#call to customize the output based on mime.
Source
# File lib/stir_fry/pages/error_page.rb, line 18 def message = error.message == error.class.name ? "" : error.message
format a message from the error
Source
# File lib/stir_fry/pages/error_page.rb, line 21 def status @status ||= case error when NotFound then :not_found when BadRequest then :bad_request when Unauthorized then :unauthorized when PreconditionFailed then :precondition_failed else :internal_server_error end end
status will derive a response status from the error raised.