I have a Grape API protected by Doorkeeper and I have a bunch of methods which work perfectly. However, there's one method that behaves weirdly. It is a GET request that requires no parameters and running it throws the following error:
Grape::Exceptions::ValidationErrors at /v1/discount_cards/all.json
id is invalid
My method looks like this:
desc 'Get all the cards of current customer'
params {}
get 'all' do
current_customer.discount_cards.to_json(include:
{
barcode: {
include: :barcode_type
}
})
end
The logs say that the error happens at line 17 of the logger.rb
file, which looks like this:
module API
class Logger
def initialize(app)
@app = app
end
def call(env)
payload = {
remote_addr: env['REMOTE_ADDR'],
request_method: env['REQUEST_METHOD'],
request_path: env['PATH_INFO'],
request_query: env['QUERY_STRING'],
x_organization: env['HTTP_X_ORGANIZATION']
}
ActiveSupport::Notifications.instrument 'grape.request', payload do
@app.call(env).tap do |response| # <-- logs say the error is here
payload[:params] = env['api.endpoint'].params.to_hash
payload[:params].delete('route_info')
payload[:params].delete('format')
payload[:response_status] = response[0]
end
end
end
end
end
My main base.rb
class looks like this:
module API
class Dispatch < Grape::API
mount API::V1::Base
end
Base = Rack::Builder.new do
use API::Logger
run API::Dispatch
end
end
I really cannot understand what id
it is talking about, and, moreover, all the other api methods work absolutely fine (post, get, put, delete).
Could you help me with resolving that issue?