Error Pages

Workarea Storefront provides an errors controller through which it routes all 404 and 500 errors, and an errors view, which it conditionally renders for HTML responses in place of the static 404 and 500 error pages provided by Rails.[1] Storefront error pages provide several advantages over the Rails defaults.

  • Each error page renders with administrable system content, specific to the error type (404 or 500)
  • The error pages use the Storefront layout, providing a consistent look and feel, as well as global functionality such as search and navigation
  • The errors view is a standard Workarea view, which you can override to extend as necessary

For these reasons, Workarea 3.3 changes error page rendering to always use Workarea error pages instead of the Rails defaults.

Use Workarea Error Pages

To use the Storefront errors view with administrable content in place of the default Rails error pages, ensure system contents with the following names exist within each environment:

  • 'Not Found' for 404 pages
  • 'Internal Server Error' for 500 pages

(Since Workarea 3.3, the errors controller creates these contents on demand, so it isn't necessary to create them in advance. However, you should create them if the retailer would like to customize the content for these pages.)

The default customer service pages seeds create these system contents within development environments. For all other environments, create these contents through any Ruby interface to which you have access (e.g. Rails console/runner/task). Refer to the example in Listing 1.

Listing 1: Excerpt from workarea-core-3.2.4/app/seeds/workarea/customer_service_pages_seeds.rb

module Workarea
  class CustomerServicePagesSeeds
    def perform
      puts 'Adding auxiliary pages...'

      <var># …</var>

      internal_error_page = Content.for('Internal Server Error')
      internal_error_page.save!

      not_found_content = Content.for('Not Found')
      not_found_content.blocks.build(
        type: :html,
        data: {
          html: '<p>Try searching or <a href="/">start at the home page</a>.</p>'
        }
      )
      not_found_content.save!
    end
  end
end

Next, edit the content for these pages within each environment and view the results.

Figure 1: Administration of the 404 system content

The admin for 404 system content

Figure 2: A Storefront 404 error page in a development environment

A 404 page in the Storefront

View Production Error Pages in Development

By default, Rails responds to an error in development with a debugging page. To view production error pages in development, you must change this behavior. Modify your application’s development configuration as shown in the following patch:

--- config/environments/development.rb.old  2018-03-20 15:37:21.000000000 -0400
+++ config/environments/development.rb  2018-03-20 15:37:04.000000000 -0400
@@ -14,7 +14,7 @@
   config.eager_load = false

   # Show full error reports.
- config.consider_all_requests_local = true
+ config.consider_all_requests_local = false

   # Enable/disable caching. By default caching is disabled.
   if Rails.root.join('tmp/caching-dev.txt').exist?

After changing your configuration, restart the application.

Notes

[1] Specifically, the paths '/404' and '/500' (regardless of HTTP method) are routed to the not_found and internal actions of the Storefront::ErrorsController, each of which conditionally renders the workarea/storefront/errors/show.html.haml view.

Now on GitHub