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