api.rb 1.9 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

N
Nihad Abbasov 已提交
6
    rescue_from ActiveRecord::RecordNotFound do
7
      rack_response({ 'message' => '404 Not found' }.to_json, 404)
N
Nihad Abbasov 已提交
8 9
    end

F
Felix Gilcher 已提交
10 11 12 13 14 15 16 17 18
    rescue_from :all do |exception|
      # lifted from https://github.com/rails/rails/blob/master/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb#L60
      # why is this not wrapped in something reusable?
      trace = exception.backtrace

      message = "\n#{exception.class} (#{exception.message}):\n"
      message << exception.annoted_source_code.to_s if exception.respond_to?(:annoted_source_code)
      message << "  " << trace.join("\n  ")

A
Andrey Kumanyaev 已提交
19
      API.logger.add Logger::FATAL, message
J
jubianchi 已提交
20
      rack_response({ 'message' => '500 Internal Server Error' }.to_json, 500)
21 22
    end

N
Nihad Abbasov 已提交
23
    format :json
24 25
    content_type :txt, "text/plain"

26 27 28
    # Ensure the namespace is right, otherwise we might load Grape::API::Helpers
    helpers ::API::Helpers

29 30 31 32 33 34
    mount ::API::AwardEmoji
    mount ::API::Branches
    mount ::API::Builds
    mount ::API::CommitStatuses
    mount ::API::Commits
    mount ::API::DeployKeys
35
    mount ::API::Environments
36
    mount ::API::Files
37
    mount ::API::GroupMembers
38 39
    mount ::API::Groups
    mount ::API::Internal
40
    mount ::API::Issues
41 42
    mount ::API::Keys
    mount ::API::Labels
43
    mount ::API::LicenseTemplates
44
    mount ::API::MergeRequests
45 46
    mount ::API::Milestones
    mount ::API::Namespaces
47 48
    mount ::API::Notes
    mount ::API::ProjectHooks
49 50 51 52 53
    mount ::API::ProjectMembers
    mount ::API::ProjectSnippets
    mount ::API::Projects
    mount ::API::Repositories
    mount ::API::Runners
54
    mount ::API::Services
55
    mount ::API::Session
56
    mount ::API::Settings
57 58 59
    mount ::API::SidekiqMetrics
    mount ::API::Subscriptions
    mount ::API::SystemHooks
60
    mount ::API::Tags
Z
ZJ van de Weg 已提交
61
    mount ::API::Templates
D
Douglas Barbosa Alexandre 已提交
62
    mount ::API::Todos
63
    mount ::API::Triggers
64
    mount ::API::Users
65
    mount ::API::Variables
N
Nihad Abbasov 已提交
66
  end
67
end