summaryrefslogtreecommitdiff
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
parent9266c3ac58404894539e25e514d8d8a6775c701f (diff)
Better error message when a database is missing (very useful for nagios tests)
-rw-r--r--app/controllers/application_controller.rb20
-rw-r--r--test/integration/api/login_test.rb2
2 files changed, 16 insertions, 6 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
##
diff --git a/test/integration/api/login_test.rb b/test/integration/api/login_test.rb
index f37639e..22047bc 100644
--- a/test/integration/api/login_test.rb
+++ b/test/integration/api/login_test.rb
@@ -14,9 +14,9 @@ class LoginTest < SrpTest
test "login with srp" do
authenticate
+ assert_nil server_auth["error"]
assert_equal ["M2", "id", "token"], server_auth.keys
assert last_response.successful?
- assert_nil server_auth["errors"]
assert server_auth["M2"]
end