Rack app error: ActionController::UnknownHttpMethodをrescueするにはどうすればいいのでしょうか?
指定されたHTTP method以外でアクセスするとこのエラーが出ます。その際に各種のバージョンなどがクライアント側に出力されるのでこれをrescueして、単純なエラーメッセージだけに変更したいと考えています。
midlewareから出されているエラーのようで
app/controllers/application_controller.rb
に
rescue_from ActionController::UnknownHttpMethod, with: :unknown_method
としても反応しません。
どうすればいいのでしょうか?
エラーログ
2016-01-06 22:22:28 +0800: Rack app error: #<ActionController::UnknownHttpMethod: AAA, accepted HTTP methods are OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT, PROPFIND, PROPPATCH, MKCOL, COPY, MOVE, LOCK, UNLOCK, VERSION-CONTROL, REPORT, CHECKOUT, CHECKIN, UNCHECKOUT, MKWORKSPACE, UPDATE, LABEL, MERGE, BASELINE-CONTROL, MKACTIVITY, ORDERPATCH, ACL, SEARCH, MKCALENDAR, and PATCH>
/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-4.2.4/lib/action_dispatch/http/request.rb:344:in `check_method'
/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-4.2.4/lib/action_dispatch/http/request.rb:105:in `request_method'
/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.4/lib/rails/rack/logger.rb:51:in `started_request_message'
/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.4/lib/rails/rack/logger.rb:37:in `block in call_app'
/.rbenv/versions/2.2.3/lib/ruby/2.2.0/logger.rb:372:in `add'
/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-4.2.4/lib/active_support/logger.rb:13:in `block (2 levels) in broadcast'
/.rbenv/versions/2.2.3/lib/ruby/2.2.0/logger.rb:434:in `info'
/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.4/lib/rails/rack/logger.rb:37:in `call_app'
/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.4/lib/rails/rack/logger.rb:20:in `block in call'
/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-4.2.4/lib/active_support/tagged_logging.rb:68:in `block in tagged'
/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-4.2.4/lib/active_support/tagged_logging.rb:26:in `tagged'
/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-4.2.4/lib/active_support/tagged_logging.rb:68:in `tagged'
/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.4/lib/rails/rack/logger.rb:20:in `call'
/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-4.2.4/lib/action_dispatch/middleware/request_id.rb:21:in `call'
/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rack-1.6.4/lib/rack/methodoverride.rb:22:in `call'
/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rack-1.6.4/lib/rack/runtime.rb:18:in `call'
/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-4.2.4/lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rack-1.6.4/lib/rack/lock.rb:17:in `call'
/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-4.2.4/lib/action_dispatch/middleware/static.rb:116:in `call'
/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rack-1.6.4/lib/rack/sendfile.rb:113:in `call'
/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.4/lib/rails/engine.rb:518:in `call'
/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.4/lib/rails/application.rb:165:in `call'
/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rack-1.6.4/lib/rack/content_length.rb:15:in `call'
/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/puma-2.15.3/lib/puma/server.rb:541:in `handle_request'
/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/puma-2.15.3/lib/puma/server.rb:388:in `process_client'
/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/puma-2.15.3/lib/puma/server.rb:270:in `block in run'
/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/puma-2.15.3/lib/puma/thread_pool.rb:106:in `call'
/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/puma-2.15.3/lib/puma/thread_pool.rb:106:in `block in spawn_thread'
Ruby 2.2.3
Rails 4.2.4
puma 2.15.3
「Rails の rescue_from で拾えない例外を exceptions_app で処理する」
http://qiita.com/ma2ge/items/938d9f8f4839eb336318
こちらを参考にしてRails.configuration.exceptions_appを設定しましたが、まったく反応せず上記のエラーログが出てきます。エラーはcurlコマンドを使って
$ curl -X AAA http://localhost:3000/
などとして例外になるようなHTTPメソッドを使ってコールしています。この時のエラーを捕捉したいのですが、まったくできません。なにがおかしいのでしょうか?