From 6696d65f6e68a9e5e2a8ab3264b242147fbd1bc0 Mon Sep 17 00:00:00 2001 From: andrew Date: Sun, 11 Nov 2007 06:42:58 +0000 Subject: [PATCH] proper error messages git-svn-id: http://svn.barleysodas.com/barleysodas/trunk@19 0f7b21a7-9e3a-4941-bbeb-ce5c7c368fa7 --- app/controllers/application.rb | 20 +++++++++++++++++++- app/controllers/beers_controller.rb | 1 + app/controllers/pages_controller.rb | 1 + 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/app/controllers/application.rb b/app/controllers/application.rb index 42ebc61..6573eb6 100644 --- a/app/controllers/application.rb +++ b/app/controllers/application.rb @@ -1,3 +1,21 @@ class ApplicationController < ActionController::Base session :session_key => '_barleysodas_session_id' -end + + ## + # Sane error and missing document messages. + # + def rescue_action_in_public(exception) + logger.debug("#{exception.class.name}: #{exception.to_s}") + exception.backtrace.each { |bt| logger.debug "! #{bt}" } + case exception + when ::ActiveRecord::RecordNotFound, + ::ActionController::UnknownController, + ::ActionController::UnknownAction, + ::ActionController::RoutingError + render :file => File.join(RAILS_ROOT, 'public/404.html'), + :status => '404 Not Found' + else + render :file => File.join(RAILS_ROOT, 'public/500.html'), + :status => '500 Error' + end + end diff --git a/app/controllers/beers_controller.rb b/app/controllers/beers_controller.rb index 672e97a..a14d272 100644 --- a/app/controllers/beers_controller.rb +++ b/app/controllers/beers_controller.rb @@ -83,6 +83,7 @@ class BeersController < ApplicationController def get_beer_and_page @beer = Beer.find_by_title(Page.title_from_url(params[:id]), :include => [ 'page' ]) + raise ActiveRecord::RecordNotFound.new if @beer.nil? @page = @beer.page end end diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb index d14b0c7..a25e81f 100644 --- a/app/controllers/pages_controller.rb +++ b/app/controllers/pages_controller.rb @@ -85,5 +85,6 @@ class PagesController < ApplicationController def fetch_page @page = Page.find_by_title(Page.title_from_url(params[:id])) + raise ActiveRecord::RecordNotFound.new if @page.nil? end end