OSDN Git Service

Merge pull request #3935 from hiroponz/fix-bubble-padding
[wvm/gitlab.git] / lib / api / api.rb
1 Dir["#{Rails.root}/lib/api/*.rb"].each {|file| require file}
2
3 module API
4   class API < Grape::API
5     version 'v3', using: :path
6
7     rescue_from ActiveRecord::RecordNotFound do
8       rack_response({'message' => '404 Not found'}.to_json, 404)
9     end
10
11     rescue_from :all do |exception|
12       # lifted from https://github.com/rails/rails/blob/master/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb#L60
13       # why is this not wrapped in something reusable?
14       trace = exception.backtrace
15
16       message = "\n#{exception.class} (#{exception.message}):\n"
17       message << exception.annoted_source_code.to_s if exception.respond_to?(:annoted_source_code)
18       message << "  " << trace.join("\n  ")
19
20       API.logger.add Logger::FATAL, message
21       rack_response({'message' => '500 Internal Server Error'}, 500)
22     end
23
24     format :json
25     helpers APIHelpers
26
27     mount Groups
28     mount Users
29     mount Projects
30     mount Issues
31     mount Milestones
32     mount Session
33     mount MergeRequests
34     mount Notes
35     mount Internal
36     mount SystemHooks
37   end
38 end