summaryrefslogtreecommitdiff
path: root/app/controllers/application_controller.rb
diff options
context:
space:
mode:
authorelijah <elijah@riseup.net>2015-03-11 15:29:43 -0700
committerelijah <elijah@riseup.net>2015-03-17 22:36:32 -0700
commitcf586771b628aea022b88b2c6d3e201338b80faf (patch)
tree8883aec893e57b5cfa27cca837d15b003f370363 /app/controllers/application_controller.rb
parent9266c3ac58404894539e25e514d8d8a6775c701f (diff)
Better error message when a database is missing (very useful for nagios tests)
Diffstat (limited to 'app/controllers/application_controller.rb')
-rw-r--r--app/controllers/application_controller.rb20
1 files changed, 15 insertions, 5 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index a4560e2..ff291f2 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -4,23 +4,33 @@ class ApplicationController < ActionController::Base
before_filter :no_cache_header
before_filter :no_frame_header
before_filter :language_header
+ rescue_from StandardError, :with => :default_error_handler
+ rescue_from RestClient::Exception, :with => :default_error_handler
ActiveSupport.run_load_hooks(:application_controller, self)
protected
- rescue_from StandardError do |e|
+ def default_error_handler(exc)
respond_to do |format|
- format.json { render_json_error(e) }
- format.all { raise e } # reraise the exception so the normal thing happens.
+ format.json { render_json_error(exc) }
+ format.all { raise exc } # reraise the exception so the normal thing happens.
end
end
+ #
+ # I think this should be 'errors', not 'error', since that is what
+ # `respond_with @object` will return. For now, I am leaving this as 'error',
+ # since there is some code that depends on this.
+ #
def render_json_error(e)
Rails.logger.error e
Rails.logger.error e.backtrace.join("\n")
- render status: 500,
- json: {error: "The server failed to process your request. We'll look into it."}
+ if e.is_a?(CouchRest::StorageMissing)
+ render status: 500, json: {error: "The database '#{e.db}' does not exist!"}
+ else
+ render status: 500, json: {error: "The server failed to process your request. We'll look into it (#{e.class})."}
+ end
end
##