From 6da528ef98eb9c65b4f52f67c03cc77b504bfe86 Mon Sep 17 00:00:00 2001 From: Fu Matthew Date: Thu, 3 Jan 2013 13:50:27 +0800 Subject: [PATCH] show error message when trying to show a not existed page --- app/controllers/application_controller.rb | 6 +++++- app/controllers/pages_controller.rb | 2 +- app/errors/page_error.rb | 3 +++ .../error_handlers/applications_error_handler.rb | 14 ++++++++++++++ .../error_handlers/page_error_handler.rb | 16 ++++++++++++++++ 5 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 app/errors/page_error.rb create mode 100644 lib/orbit_app/error_handlers/applications_error_handler.rb create mode 100644 lib/orbit_app/error_handlers/page_error_handler.rb diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 8bb94384..47cacb11 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -2,9 +2,13 @@ class ApplicationController < ActionController::Base protect_from_forgery include ParserFrontEnd, ParserBackEnd, ApplicationHelper - include OrbitApp::ErrorHandlers + include OrbitApp::ErrorHandlers::PageErrorHandler + include OrbitApp::ErrorHandlers::ObjectAuthErrorHandler + include OrbitApp::ErrorHandlers::ModuleAppErrorHandler + rescue_from ObjectAuthError, :with => :render_object_auth_error rescue_from ModuleAppError, :with => :render_module_app_error + rescue_from PageError, :with => :render_page_error layout :layout_by_resource diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb index dada6152..e591b331 100644 --- a/app/controllers/pages_controller.rb +++ b/app/controllers/pages_controller.rb @@ -76,7 +76,7 @@ class PagesController < ApplicationController end @item = Item.where(module_app_id: module_app.id,app_frontend_url:params[:app_action]).all_of("tag" => {"$in" => [nil,'']},"category" => { "$in" => [nil,'']}).first unless @item @item = Item.where(module_app_id: module_app.id,app_frontend_url:params[:app_action]).first unless @item - #TODO 需要做 error handler 處理沒有新增該模組頁面導致錯誤的可能性 + raise PageError,'Missing Frontend Page' end def save_from_no_lang_for_page diff --git a/app/errors/page_error.rb b/app/errors/page_error.rb new file mode 100644 index 00000000..bf156f6a --- /dev/null +++ b/app/errors/page_error.rb @@ -0,0 +1,3 @@ +class PageError < StandardError + +end \ No newline at end of file diff --git a/lib/orbit_app/error_handlers/applications_error_handler.rb b/lib/orbit_app/error_handlers/applications_error_handler.rb new file mode 100644 index 00000000..2748f8c4 --- /dev/null +++ b/lib/orbit_app/error_handlers/applications_error_handler.rb @@ -0,0 +1,14 @@ + +# require "#{File.dirname(__FILE__)}/module_app_error_handler.rb" +# require "#{File.dirname(__FILE__)}/object_auth_error_handler.rb" +# require "#{File.dirname(__FILE__)}/module_app_error_handler.rb" +# require "#{File.dirname(__FILE__)}/page_error_handler.rb" + + +# module OrbitApp +# module ErrorHandlers +# module ApplicationsErrorHandler + +# end +# end +# end diff --git a/lib/orbit_app/error_handlers/page_error_handler.rb b/lib/orbit_app/error_handlers/page_error_handler.rb new file mode 100644 index 00000000..5bf76ba6 --- /dev/null +++ b/lib/orbit_app/error_handlers/page_error_handler.rb @@ -0,0 +1,16 @@ +module OrbitApp + module ErrorHandlers + module PageErrorHandler + + + def render_page_error(exception = nil) + default_message = 'ModuleAppErrorHandler' + meaasge = '' + if exception + meaasge = default_message + exception.message + end + render :text=>meaasge + end + end + end +end