diff options
author | Rhenium <rhenium@rhe.jp> | 2014-03-11 21:23:02 +0900 |
---|---|---|
committer | Rhenium <rhenium@rhe.jp> | 2014-03-11 21:23:02 +0900 |
commit | 7c392ca7735a36948515a392b544ace60a242838 (patch) | |
tree | 7d887731c549decf33d23018268e5e974b16a2cd /app/controllers/errors_controller.rb | |
parent | 71c2069595618cb048c8e04c577902c08fc20a57 (diff) | |
download | aclog-7c392ca7735a36948515a392b544ace60a242838.tar.gz |
reorganize exceptions
Diffstat (limited to 'app/controllers/errors_controller.rb')
-rw-r--r-- | app/controllers/errors_controller.rb | 22 |
1 files changed, 6 insertions, 16 deletions
diff --git a/app/controllers/errors_controller.rb b/app/controllers/errors_controller.rb index 8328388..f59c6e5 100644 --- a/app/controllers/errors_controller.rb +++ b/app/controllers/errors_controller.rb @@ -1,42 +1,32 @@ class ErrorsController < ApplicationController before_action :force_format - layout :select_layout def render_error @exception = env["action_dispatch.exception"] case @exception - when OAuth::Unauthorized - # only /i/callback: when Cancel pressed on Twitter's OAuth - redirect_to root_path - when Aclog::Exceptions::LoginRequired, - Aclog::Exceptions::UserProtected, - Aclog::Exceptions::AccountPrivate + when Aclog::Exceptions::Forbidden @status = 403 @message = t("error.forbidden") when ActionController::RoutingError, ActiveRecord::RecordNotFound, ActionView::MissingTemplate, - Aclog::Exceptions::UserNotRegistered + Aclog::Exceptions::NotFound @status = 404 @message = t("error.not_found") + when OAuth::Unauthorized, + Aclog::Exceptions::Unauthorized + @status = 401 + @message = "" else @status = 500 @message = "#{t("error.internal_error")}: #{@exception.class}" end - if @exception.is_a? Aclog::Exceptions::UserError - @user = @exception.user - end - render status: @status end private - def select_layout - @user ? nil : "index" - end - def force_format request.format = (env["REQUEST_PATH"].scan(/\.([A-Za-z]+)$/).flatten.first || :html).to_sym |