문제

I use Airbrake to notify me about errors in my Spree Commerce shop. Now that I want to use the API of spree, I get the following error, when I try to post to http://localhost:3000/api/products to create a new product:

NoMethodError (undefined method `airbrake_request_data' for #<Spree::Api::V1::ProductsController:0x007f9fcdb81b58>):
  activesupport (3.2.9) lib/active_support/core_ext/object/try.rb:36:in `try'
  airbrake (3.1.11) lib/airbrake/rails/middleware.rb:46:in `request_data'
  airbrake (3.1.11) lib/airbrake/rails/middleware.rb:39:in `notify_airbrake'
  airbrake (3.1.11) lib/airbrake/rails/middleware.rb:15:in `rescue in call'
  airbrake (3.1.11) lib/airbrake/rails/middleware.rb:12:in `call'
  actionpack (3.2.9) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
  actionpack (3.2.9) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
  railties (3.2.9) lib/rails/rack/logger.rb:32:in `call_app'
  railties (3.2.9) lib/rails/rack/logger.rb:16:in `block in call'
  activesupport (3.2.9) lib/active_support/tagged_logging.rb:22:in `tagged'
  railties (3.2.9) lib/rails/rack/logger.rb:16:in `call'
  actionpack (3.2.9) lib/action_dispatch/middleware/request_id.rb:22:in `call'
  rack (1.4.5) lib/rack/methodoverride.rb:21:in `call'
  rack (1.4.5) lib/rack/runtime.rb:17:in `call'
  activesupport (3.2.9) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
  rack (1.4.5) lib/rack/lock.rb:15:in `call'
  actionpack (3.2.9) lib/action_dispatch/middleware/static.rb:62:in `call'
  airbrake (3.1.11) lib/airbrake/user_informer.rb:16:in `_call'
  airbrake (3.1.11) lib/airbrake/user_informer.rb:12:in `call'
  railties (3.2.9) lib/rails/engine.rb:479:in `call'
  railties (3.2.9) lib/rails/application.rb:223:in `call'
  rack (1.4.5) lib/rack/content_length.rb:14:in `call'
  railties (3.2.9) lib/rails/rack/log_tailer.rb:17:in `call'
  rack (1.4.5) lib/rack/handler/webrick.rb:59:in `service'
  /usr/local/rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
  /usr/local/rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
  /usr/local/rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'


  Rendered /usr/local/rvm/gems/ruby-1.9.3-p392@system/gems/actionpack-3.2.9/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.4ms)
  Rendered /usr/local/rvm/gems/ruby-1.9.3-p392@system/gems/actionpack-3.2.9/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (16.6ms)
  Rendered /usr/local/rvm/gems/ruby-1.9.3-p392@system/gems/actionpack-3.2.9/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (55.2ms)

Obviously, there is an error in my call. But I want to know which error. And of course, Airbrake should also notify errors from the API. I configured Airbrake with Spree so:

Gemfile

gem "airbrake"

initializers/airbrake.rb

Airbrake.configure do |config|
  config.api_key = 'XXXXXXXXXXXXXXXXXXX'
end

So, a simple setup. I'm using Spree 1-2-stable, and I have no idea where to start to solve this problem.

도움이 되었습니까?

해결책

You're encountering this error because the Spree API extends ActionController::Metal instead of ActionController::Base.

The airbrake gem performs some logic shown here: https://github.com/airbrake/airbrake/blob/68543097a8731cf1f3e717946bd5ed33e5edccad/lib/airbrake/rails.rb#L13

which includes methods in to ActionController::Base.

You have a few options on how to get around this:

  1. Load the methods in to ActionController::Metal as well using a similar method to that shown in the airbrake gem
  2. Load the methods in to Spree::Api::BaseController using a similar method
  3. Decorate Spree::Api::BaseController to include the methods directly

That should get you going.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top