api.rb 1.96 KB
Newer Older
1
module API
Nihad Abbasov's avatar
Nihad Abbasov committed
2
  class API < Grape::API
Valery Sizov's avatar
Valery Sizov committed
3
    include APIGuard
Riyad Preukschas's avatar
Riyad Preukschas committed
4
    version 'v3', using: :path
Nihad Abbasov's avatar
Nihad Abbasov committed
5

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

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

Connor Shea's avatar
Connor Shea committed
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

20
    rescue_from :all do |exception|
Stan Hu's avatar
Stan Hu committed
21
      handle_api_exception(exception)
22 23
    end

Nihad Abbasov's avatar
Nihad Abbasov committed
24
    format :json
25 26
    content_type :txt, "text/plain"

27
    # Ensure the namespace is right, otherwise we might load Grape::API::Helpers
Stan Hu's avatar
Stan Hu committed
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.J. van de Weg's avatar
Z.J. van de Weg committed
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::Members
49
    mount ::API::MergeRequests
50 51
    mount ::API::Milestones
    mount ::API::Namespaces
52
    mount ::API::Notes
53
    mount ::API::Pipelines
54
    mount ::API::ProjectHooks
55 56 57 58
    mount ::API::ProjectSnippets
    mount ::API::Projects
    mount ::API::Repositories
    mount ::API::Runners
59
    mount ::API::Services
60
    mount ::API::Session
61
    mount ::API::Settings
62 63 64
    mount ::API::SidekiqMetrics
    mount ::API::Subscriptions
    mount ::API::SystemHooks
65
    mount ::API::Tags
66
    mount ::API::Templates
Douglas Barbosa Alexandre's avatar
Douglas Barbosa Alexandre committed
67
    mount ::API::Todos
68
    mount ::API::Triggers
69
    mount ::API::Users
70
    mount ::API::Variables
71
    mount ::API::MergeRequestDiffs
Nihad Abbasov's avatar
Nihad Abbasov committed
72
  end
73
end