BigW Consortium Gitlab

api.rb 1.51 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
Valery Sizov committed
5
    include APIGuard
Riyad Preukschas committed
6
    version 'v3', using: :path
Nihad Abbasov committed
7

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

12 13 14 15 16 17 18 19 20
    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  ")

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

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

28
    helpers Helpers
29

30
    mount Groups
31
    mount GroupMembers
32 33
    mount Users
    mount Projects
34
    mount Repositories
Nihad Abbasov committed
35
    mount Issues
Robert Speicher committed
36
    mount Milestones
37
    mount Session
38
    mount MergeRequests
39
    mount Notes
Dmitriy Zaporozhets committed
40
    mount Internal
Matt Humphrey committed
41
    mount SystemHooks
42
    mount ProjectSnippets
43
    mount ProjectMembers
44 45
    mount DeployKeys
    mount ProjectHooks
46
    mount Services
47
    mount Files
48
    mount Commits
49
    mount CommitStatus
50
    mount Namespaces
51
    mount Branches
52
    mount Labels
53
    mount Settings
54
    mount Keys
55
    mount Tags
56
    mount Triggers
57
    mount Builds
58
    mount Variables
59
    mount Runners
Nihad Abbasov committed
60
  end
61
end