Home Grape API won't mount after upgrade - constant missing
Reply: 0

Grape API won't mount after upgrade - constant missing

user2666194
1#
user2666194 Published in 2017-11-29 13:25:24Z

I'm having issues upgrading from grape 0.19.2 to 1.0.1. I receive the following error message when starting the server. The upgrade document does not specify changes that seem to break my current setup.

Note: grape 1.0.0 does not have the issue.

/Users/johndoe/.rvm/gems/ruby-2.2.5@vip_rails_42/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:364:in `rescue in require_or_load': exception reentered (fatal)
    from /Users/johndoe/.rvm/gems/ruby-2.2.5@vip_rails_42/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:367:in `require_or_load'
    from /Users/johndoe/.rvm/gems/ruby-2.2.5@vip_rails_42/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:494:in `load_missing_constant'
    from /Users/johndoe/.rvm/gems/ruby-2.2.5@vip_rails_42/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:184:in `const_missing'
    from /Users/johndoe/GitHub/Website/app/api/mobile/base.rb:7:in `<class:Dispatch>'
    from /Users/johndoe/GitHub/Website/app/api/mobile/base.rb:4:in `<module:Mobile>'
    from /Users/johndoe/GitHub/Website/app/api/mobile/base.rb:3:in `<top (required)>'
    from /Users/johndoe/.rvm/gems/ruby-2.2.5@vip_rails_42/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:457:in `load'
    from /Users/johndoe/.rvm/gems/ruby-2.2.5@vip_rails_42/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:457:in `block in load_file'
    from /Users/johndoe/.rvm/gems/ruby-2.2.5@vip_rails_42/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:647:in `new_constants_in'
    from /Users/johndoe/.rvm/gems/ruby-2.2.5@vip_rails_42/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:456:in `load_file'
    from /Users/johndoe/.rvm/gems/ruby-2.2.5@vip_rails_42/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:354:in `require_or_load'
    from /Users/johndoe/.rvm/gems/ruby-2.2.5@vip_rails_42/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:494:in `load_missing_constant'
    from /Users/johndoe/.rvm/gems/ruby-2.2.5@vip_rails_42/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:184:in `const_missing'
    from /Users/johndoe/GitHub/Website/config/routes.rb:18:in `block in <top (required)>'
....

/app/api/mobile/base.rb

require 'grape-swagger'

module Mobile
  class Dispatch < Grape::API
    #mount Mobile::V1::Root
    #mount Mobile::V2::Root
    mount Mobile::V3::Root
    format :json
    route :any, '*path' do
      Rack::Response.new({message: 'Not found'}.to_json, 404).finish
    end
    add_swagger_documentation
  end

  Base = Rack::Builder.new do
    use Mobile::Logger
    run Mobile::Dispatch
  end
end

/app/api/mobile/v3/root.rb

module Mobile
  module V3
    class Root < Dispatch

      format :json
      # formatter :json, Grape::Formatter::ActiveModelSerializers
      version 'v3'
      default_error_formatter :json
      content_type :json, 'application/json'
      use ::WineBouncer::OAuth2

      rescue_from :all do |e|
        eclass = e.class.to_s
        message = "OAuth error: #{e.to_s}" if eclass.match('WineBouncer::Errors')
        status = case 
        when eclass.match('OAuthUnauthorizedError')
          401
        when eclass.match('OAuthForbiddenError')
          403
        when eclass.match('RecordNotFound'), e.message.match(/unable to find/i).present?
          404
        else
          (e.respond_to? :status) && e.status || 500
        end
        opts = { error: "#{message || e.message}" }
        opts[:trace] = e.backtrace[0,10] unless Rails.env.production?
        Rack::Response.new(opts.to_json, status, {
          'Content-Type' => "application/json",
          'Access-Control-Allow-Origin' => '*',
          'Access-Control-Request-Method' => '*',
        }).finish
      end

      mount Mobile::V3::Me
      mount Mobile::V3::Areas
      mount Mobile::V3::Events
      mount Mobile::V3::Eventdays
      mount Mobile::V3::Positions
      mount Mobile::V3::Signups
      mount Mobile::V3::Mailbox

      add_swagger_documentation base_path: "/api",
                                api_version: 'v3',
                                hide_format: true, # don't show .json
                                hide_documentation_path: true,
                                mount_path: '/swagger_doc',
                                # markdown: GrapeSwagger::Markdown::KramdownAdapter,
                                info: {
                                    title: 'Grape Swagger base app',
                                    description: 'This is the base api provided by the awesome sample app - https://github.com/sethherr/grape-doorkeeper',
                                  }

      route :any, '*path' do
        raise StandardError, 'Unable to find endpoint'
      end
    end
  end
end

The crash happens at line:

mount Mobile::V3::Me

because the Mobile::V3::Me constant is not found.

/app/api/mobile/v3/me.rb

module Mobile
  module V3
    class Me < Mobile::V3::Root
      include Mobile::V3::Defaults

      resource :me, desc: 'Operations about the current user' do

.....

      end

    end
  end
end

Folder structure

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.537337 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO