api.rb 2.4 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
    # Retain 405 error rather than a 500 error for Grape 0.15.0+.
17 18 19 20 21
    # https://github.com/ruby-grape/grape/blob/a3a28f5b5dfbb2797442e006dbffd750b27f2a76/UPGRADING.md#changes-to-method-not-allowed-routes
    rescue_from Grape::Exceptions::MethodNotAllowed do |e|
      error! e.message, e.status, e.headers
    end

C
Connor Shea 已提交
22 23
    rescue_from Grape::Exceptions::Base do |e|
      error! e.message, e.status, e.headers
24 25
    end

F
Felix Gilcher 已提交
26
    rescue_from :all do |exception|
S
Stan Hu 已提交
27
      handle_api_exception(exception)
28 29
    end

N
Nihad Abbasov 已提交
30
    format :json
31 32
    content_type :txt, "text/plain"

33
    # Ensure the namespace is right, otherwise we might load Grape::API::Helpers
S
Stan Hu 已提交
34
    helpers ::SentryHelper
35 36
    helpers ::API::Helpers

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

    route :any, '*path' do
85
      error!('404 Not Found', 404)
86
    end
N
Nihad Abbasov 已提交
87
  end
88
end