api.rb 1.9 KB
Newer Older
1
module API
N
Nihad Abbasov 已提交
2
  class API < Grape::API
V
Valery Sizov 已提交
3
    include APIGuard
R
Riyad Preukschas 已提交
4
    version 'v3', using: :path
N
Nihad Abbasov 已提交
5

6 7 8 9
    rescue_from Gitlab::Access::AccessDeniedError do
      rack_response({ 'message' => '403 Forbidden' }.to_json, 403)
    end

N
Nihad Abbasov 已提交
10
    rescue_from ActiveRecord::RecordNotFound do
11
      rack_response({ 'message' => '404 Not found' }.to_json, 404)
N
Nihad Abbasov 已提交
12 13
    end

C
Connor Shea 已提交
14 15 16 17
    # Retain 405 error rather than a 500 error for Grape 0.15.0+.
    # See: https://github.com/ruby-grape/grape/commit/252bfd27c320466ec3c0751812cf44245e97e5de
    rescue_from Grape::Exceptions::Base do |e|
      error! e.message, e.status, e.headers
18 19
    end

F
Felix Gilcher 已提交
20
    rescue_from :all do |exception|
S
Stan Hu 已提交
21
      handle_api_exception(exception)
22 23
    end

N
Nihad Abbasov 已提交
24
    format :json
25 26
    content_type :txt, "text/plain"

27
    # Ensure the namespace is right, otherwise we might load Grape::API::Helpers
S
Stan Hu 已提交
28
    helpers ::SentryHelper
29 30
    helpers ::API::Helpers

31
    mount ::API::AccessRequests
32 33 34 35 36 37
    mount ::API::AwardEmoji
    mount ::API::Branches
    mount ::API::Builds
    mount ::API::CommitStatuses
    mount ::API::Commits
    mount ::API::DeployKeys
Z
Z.J. van de Weg 已提交
38
    mount ::API::Deployments
39
    mount ::API::Environments
40 41 42
    mount ::API::Files
    mount ::API::Groups
    mount ::API::Internal
43
    mount ::API::Issues
44 45
    mount ::API::Keys
    mount ::API::Labels
46
    mount ::API::LicenseTemplates
47
    mount ::API::Members
48
    mount ::API::MergeRequests
49 50
    mount ::API::Milestones
    mount ::API::Namespaces
51
    mount ::API::Notes
Z
Z.J. van de Weg 已提交
52
    mount ::API::Pipelines
53
    mount ::API::ProjectHooks
54 55 56 57
    mount ::API::ProjectSnippets
    mount ::API::Projects
    mount ::API::Repositories
    mount ::API::Runners
58
    mount ::API::Services
59
    mount ::API::Session
60
    mount ::API::Settings
61 62 63
    mount ::API::SidekiqMetrics
    mount ::API::Subscriptions
    mount ::API::SystemHooks
64
    mount ::API::Tags
Z
ZJ van de Weg 已提交
65
    mount ::API::Templates
D
Douglas Barbosa Alexandre 已提交
66
    mount ::API::Todos
67
    mount ::API::Triggers
68
    mount ::API::Users
69
    mount ::API::Variables
70
    mount ::API::MergeRequestDiffs
N
Nihad Abbasov 已提交
71
  end
72
end