api.rb 2.2 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
    before { allow_access_with_scope :api }

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

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

C
Connor Shea 已提交
16 17 18 19
    # 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
20 21
    end

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

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

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

33
    # Keep in alphabetical order
34
    mount ::API::AccessRequests
35
    mount ::API::AwardEmoji
R
Robert Schilling 已提交
36
    mount ::API::Boards
37
    mount ::API::Branches
38
    mount ::API::BroadcastMessages
39 40
    mount ::API::Builds
    mount ::API::Commits
R
Robert Schilling 已提交
41
    mount ::API::CommitStatuses
42
    mount ::API::DeployKeys
Z
Z.J. van de Weg 已提交
43
    mount ::API::Deployments
44
    mount ::API::Environments
45 46 47
    mount ::API::Files
    mount ::API::Groups
    mount ::API::Internal
48
    mount ::API::Issues
49 50
    mount ::API::Keys
    mount ::API::Labels
51
    mount ::API::Lint
52
    mount ::API::Members
53
    mount ::API::MergeRequestDiffs
R
Robert Schilling 已提交
54
    mount ::API::MergeRequests
55 56
    mount ::API::Milestones
    mount ::API::Namespaces
57
    mount ::API::Notes
58
    mount ::API::NotificationSettings
Z
Z.J. van de Weg 已提交
59
    mount ::API::Pipelines
60
    mount ::API::ProjectHooks
61
    mount ::API::Projects
R
Robert Schilling 已提交
62
    mount ::API::ProjectSnippets
63 64
    mount ::API::Repositories
    mount ::API::Runners
65
    mount ::API::Services
66
    mount ::API::Session
67
    mount ::API::Settings
68
    mount ::API::SidekiqMetrics
69
    mount ::API::Snippets
70 71
    mount ::API::Subscriptions
    mount ::API::SystemHooks
72
    mount ::API::Tags
Z
ZJ van de Weg 已提交
73
    mount ::API::Templates
D
Douglas Barbosa Alexandre 已提交
74
    mount ::API::Todos
75
    mount ::API::Triggers
76
    mount ::API::Users
77
    mount ::API::Variables
R
Robert Schilling 已提交
78
    mount ::API::Version
79 80

    route :any, '*path' do
81
      error!('404 Not Found', 404)
82
    end
N
Nihad Abbasov 已提交
83
  end
84
end