api.rb 1.5 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
V
Valery Sizov 已提交
5
    include APIGuard
R
Riyad Preukschas 已提交
6
    version 'v3', using: :path
N
Nihad Abbasov 已提交
7

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

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

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

J
Jason Lee 已提交
28
    helpers Helpers
A
Andrey Kumanyaev 已提交
29

30
    mount Groups
D
Dmitriy Zaporozhets 已提交
31
    mount GroupMembers
N
Nihad Abbasov 已提交
32 33
    mount Users
    mount Projects
34
    mount Repositories
N
Nihad Abbasov 已提交
35
    mount Issues
R
Robert Speicher 已提交
36
    mount Milestones
37
    mount Session
V
Valeriy Sizov 已提交
38
    mount MergeRequests
39
    mount Notes
D
Dmitriy Zaporozhets 已提交
40
    mount Internal
M
Matt Humphrey 已提交
41
    mount SystemHooks
42
    mount ProjectSnippets
43
    mount ProjectMembers
44 45
    mount DeployKeys
    mount ProjectHooks
46
    mount Services
D
Dmitriy Zaporozhets 已提交
47
    mount Files
48
    mount Commits
K
Kamil Trzcinski 已提交
49
    mount CommitStatus
50
    mount Namespaces
51
    mount Branches
R
Robert Schilling 已提交
52
    mount Labels
53
    mount Settings
54
    mount Keys
55
    mount Tags
K
Kamil Trzcinski 已提交
56
    mount Triggers
57
    mount Builds
58
    mount Variables
59
    mount Runners
60
    mount Licenses
N
Nihad Abbasov 已提交
61
  end
62
end