BigW Consortium Gitlab

api.rb 1.28 KB
Newer Older
1
Dir["#{Rails.root}/lib/api/*.rb"].each {|file| require file}
Nihad Abbasov committed
2

3
module API
Nihad Abbasov committed
4
  class API < Grape::API
Riyad Preukschas committed
5
    version 'v3', using: :path
Nihad Abbasov committed
6

7 8 9 10
    rescue_from ActiveRecord::RecordNotFound do
      rack_response({'message' => '404 Not found'}.to_json, 404)
    end

11 12 13 14 15 16 17 18 19
    rescue_from :all do |exception|
      # lifted from https://github.com/rails/rails/blob/master/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb#L60
      # why is this not wrapped in something reusable?
      trace = exception.backtrace

      message = "\n#{exception.class} (#{exception.message}):\n"
      message << exception.annoted_source_code.to_s if exception.respond_to?(:annoted_source_code)
      message << "  " << trace.join("\n  ")

20
      API.logger.add Logger::FATAL, message
21 22 23
      rack_response({'message' => '500 Internal Server Error'}, 500)
    end

Nihad Abbasov committed
24
    format :json
25 26
    content_type :txt, "text/plain"

Nihad Abbasov committed
27
    helpers APIHelpers
28

29
    mount Groups
30 31
    mount Users
    mount Projects
32
    mount Repositories
Nihad Abbasov committed
33
    mount Issues
Robert Speicher committed
34
    mount Milestones
35
    mount Session
36
    mount MergeRequests
37
    mount Notes
Dmitriy Zaporozhets committed
38
    mount Internal
Matt Humphrey committed
39
    mount SystemHooks
40
    mount ProjectSnippets
41
    mount ProjectMembers
42 43
    mount DeployKeys
    mount ProjectHooks
44
    mount Services
45
    mount Files
46
    mount Commits
47
    mount Namespaces
Nihad Abbasov committed
48
  end
49
end