From 89b64a44f269bb6dfe68cdff8a168ee2a04ee9d6 Mon Sep 17 00:00:00 2001 From: mo khan Date: Sat, 22 Feb 2014 09:06:00 -0700 Subject: add global error handler to respond with internal server error. --- app/controllers/application_controller.rb | 8 ++++++++ spec/controllers/application_controller_spec.rb | 9 +++++++++ 2 files changed, 17 insertions(+) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 658a065..1b2f9f7 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -3,9 +3,17 @@ class ApplicationController < ActionController::Base # For APIs, you may want to use :null_session instead. protect_from_forgery with: :null_session before_filter :load_additional_payload_data + rescue_from StandardError, with: :return_server_error + def load_additional_payload_data @license_statuses = LicenseStatus::ALL @well_types = WellType::ALL end + + private + + def return_server_error + render nothing: true, status: :internal_server_error + end end diff --git a/spec/controllers/application_controller_spec.rb b/spec/controllers/application_controller_spec.rb index a26c465..7ccca09 100644 --- a/spec/controllers/application_controller_spec.rb +++ b/spec/controllers/application_controller_spec.rb @@ -5,6 +5,10 @@ describe ApplicationController do def index render nothing: true end + + def show + raise "heck" + end end it "includes all well statuses with every response" do @@ -16,4 +20,9 @@ describe ApplicationController do get :index assigns(:well_types).should =~ WellType::ALL end + + it "handles errors gracefully" do + get :show, id: 1 + response.status.should == 500 + end end -- cgit v1.2.3