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

    route :any, '*path' do
      error!('400 Bad Request', 400)
    end
N
Nihad Abbasov 已提交
80
  end
81
end