summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAzul <azul@riseup.net>2016-11-21 16:14:38 +0100
committerAzul <azul@riseup.net>2017-03-23 09:49:17 +0100
commit1e672227a23afbb9f319a0aefa0b0ca3495fa1c6 (patch)
treef16e3d9f830cef89d523ef2da66fd27bb2afd426
parent3efe125d6e3bd5f4eecd18952376ffc37e09b9c5 (diff)
bugfix: handle couch 404s
our special error handler for json requests would turn all exceptions into 500s - removed it. now the rescue_responses can do their thing again.
-rw-r--r--app/controllers/application_controller.rb10
-rw-r--r--app/controllers/errors_controller.rb2
-rw-r--r--app/views/errors/server_error.json4
-rw-r--r--config/application.rb8
-rw-r--r--lib/extensions/couchrest.rb6
-rw-r--r--test/functional/error_handling_test.rb22
-rw-r--r--test/integration/api/update_account_test.rb8
7 files changed, 18 insertions, 42 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 8d08a2c..1f37fea 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -10,9 +10,6 @@ class ApplicationController < ActionController::Base
# rendered and that template is not present
before_filter :verify_request_format!, if: :mime_types_specified
- rescue_from StandardError, :with => :default_error_handler
- rescue_from CouchRest::Exception, :with => :default_error_handler
-
ActiveSupport.run_load_hooks(:application_controller, self)
protected
@@ -22,13 +19,6 @@ class ApplicationController < ActionController::Base
mimes.present?
end
- def default_error_handler(exc)
- respond_to do |format|
- 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',
diff --git a/app/controllers/errors_controller.rb b/app/controllers/errors_controller.rb
index 80c270f..2d918b5 100644
--- a/app/controllers/errors_controller.rb
+++ b/app/controllers/errors_controller.rb
@@ -1,6 +1,4 @@
-# We render http errors ourselves so we can customize them
class ErrorsController < ApplicationController
- respond_to :html
# 404
def not_found
diff --git a/app/views/errors/server_error.json b/app/views/errors/server_error.json
index d9a1a86..a2763f6 100644
--- a/app/views/errors/server_error.json
+++ b/app/views/errors/server_error.json
@@ -1,4 +1,4 @@
{
- "error": "server_error",
+ "error": "server failed",
"message": "Server Error"
-} \ No newline at end of file
+}
diff --git a/config/application.rb b/config/application.rb
index 0e00356..d8e4c82 100644
--- a/config/application.rb
+++ b/config/application.rb
@@ -22,6 +22,7 @@ APP_CONFIG = ["defaults.yml", "config.yml"].inject({}) {|config, file|
module LeapWeb
class Application < Rails::Application
+
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
@@ -53,7 +54,14 @@ module LeapWeb
end
config.paths['app/views'].unshift custom_view_path
+
+ config.action_dispatch.rescue_responses.merge!(
+ 'CouchRest::Model::DocumentNotFound' => :not_found,
+ 'CouchRest::NotFound' => :not_found
+ )
+
# handle http errors ourselves
config.exceptions_app = self.routes
+
end
end
diff --git a/lib/extensions/couchrest.rb b/lib/extensions/couchrest.rb
index 4578926..1734f3b 100644
--- a/lib/extensions/couchrest.rb
+++ b/lib/extensions/couchrest.rb
@@ -78,10 +78,4 @@ module CouchRest
end
- class ModelRailtie
- config.action_dispatch.rescue_responses.merge!(
- 'CouchRest::Model::DocumentNotFound' => :not_found,
- 'CouchRest::NotFound' => :not_found
- )
- end
end
diff --git a/test/functional/error_handling_test.rb b/test/functional/error_handling_test.rb
deleted file mode 100644
index 47e44ce..0000000
--- a/test/functional/error_handling_test.rb
+++ /dev/null
@@ -1,22 +0,0 @@
-require 'test_helper'
-
-class ErrorHandlingTest < ActionController::TestCase
- tests HomeController
-
- def setup
- HomeController.any_instance.stubs(:index).raises
- end
-
- def test_json_error
- get :index, format: :json
- assert_equal 'application/json', @response.content_type
- assert json = JSON.parse(@response.body)
- assert_equal ['error'], json.keys
- end
-
- def test_html_error_reraises
- assert_raises RuntimeError do
- get :index
- end
- end
-end
diff --git a/test/integration/api/update_account_test.rb b/test/integration/api/update_account_test.rb
index 108f05d..f083dbc 100644
--- a/test/integration/api/update_account_test.rb
+++ b/test/integration/api/update_account_test.rb
@@ -54,4 +54,12 @@ class UpdateAccountTest < SrpTest
# does not change login if no password_verifier is present
assert_equal original_login, @user.reload.login
end
+
+ test "destroy account" do
+ authenticate
+ url = api_url("users/#{@user.id}.json?identities=destroy")
+ delete url, nil, auth_headers
+ assert last_response.successful?
+ end
+
end