api.rb 1.1 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 25
    format :json
    helpers APIHelpers
A
Andrey Kumanyaev 已提交
26

27
    mount Groups
N
Nihad Abbasov 已提交
28 29
    mount Users
    mount Projects
30
    mount Repositories
N
Nihad Abbasov 已提交
31
    mount Issues
R
Robert Speicher 已提交
32
    mount Milestones
33
    mount Session
V
Valeriy Sizov 已提交
34
    mount MergeRequests
35
    mount Notes
D
Dmitriy Zaporozhets 已提交
36
    mount Internal
M
Matt Humphrey 已提交
37
    mount SystemHooks
C
Christian Simon 已提交
38
    mount UserTeams
N
Nihad Abbasov 已提交
39
  end
40
end