api.rb 1.3 KB
Newer Older
N
Nihad Abbasov 已提交
1
Dir["#{Rails.root}/lib/api/*.rb"].each {|file| require file}
N
Nihad Abbasov 已提交
2

3
module API
N
Nihad Abbasov 已提交
4
  class API < Grape::API
R
Riyad Preukschas 已提交
5
    version 'v3', using: :path
N
Nihad Abbasov 已提交
6

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

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

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

N
Nihad Abbasov 已提交
27
    helpers APIHelpers
A
Andrey Kumanyaev 已提交
28

29
    mount Groups
D
Dmitriy Zaporozhets 已提交
30
    mount GroupMembers
N
Nihad Abbasov 已提交
31 32
    mount Users
    mount Projects
33
    mount Repositories
N
Nihad Abbasov 已提交
34
    mount Issues
R
Robert Speicher 已提交
35
    mount Milestones
36
    mount Session
V
Valeriy Sizov 已提交
37
    mount MergeRequests
38
    mount Notes
D
Dmitriy Zaporozhets 已提交
39
    mount Internal
M
Matt Humphrey 已提交
40
    mount SystemHooks
41
    mount ProjectSnippets
42
    mount ProjectMembers
43 44
    mount DeployKeys
    mount ProjectHooks
45
    mount Services
D
Dmitriy Zaporozhets 已提交
46
    mount Files
47
    mount Commits
48
    mount Namespaces
49
    mount Branches
R
Robert Schilling 已提交
50
    mount Labels
N
Nihad Abbasov 已提交
51
  end
52
end