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

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

10 11 12 13
    rescue_from Grape::Exceptions::ValidationErrors do |e|
      error!({ messages: e.full_messages }, 400)
    end

F
Felix Gilcher 已提交
14 15 16 17 18 19 20 21 22
    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 已提交
23
      API.logger.add Logger::FATAL, message
J
jubianchi 已提交
24
      rack_response({ 'message' => '500 Internal Server Error' }.to_json, 500)
25 26
    end

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

30 31 32
    # Ensure the namespace is right, otherwise we might load Grape::API::Helpers
    helpers ::API::Helpers

33 34 35 36 37 38
    mount ::API::AwardEmoji
    mount ::API::Branches
    mount ::API::Builds
    mount ::API::CommitStatuses
    mount ::API::Commits
    mount ::API::DeployKeys
39
    mount ::API::Environments
40
    mount ::API::Files
41
    mount ::API::GroupMembers
42 43
    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::MergeRequests
49 50
    mount ::API::Milestones
    mount ::API::Namespaces
51 52
    mount ::API::Notes
    mount ::API::ProjectHooks
53 54 55 56 57
    mount ::API::ProjectMembers
    mount ::API::ProjectSnippets
    mount ::API::Projects
    mount ::API::Repositories
    mount ::API::Runners
58
    mount ::API::Services
59
    mount ::API::Session
60
    mount ::API::Settings
61 62 63
    mount ::API::SidekiqMetrics
    mount ::API::Subscriptions
    mount ::API::SystemHooks
64
    mount ::API::Tags
Z
ZJ van de Weg 已提交
65
    mount ::API::Templates
D
Douglas Barbosa Alexandre 已提交
66
    mount ::API::Todos
67
    mount ::API::Triggers
68
    mount ::API::Users
69
    mount ::API::Variables
N
Nihad Abbasov 已提交
70
  end
71
end