api.rb 1.8 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

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

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

26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
    # Ensure the namespace is right, otherwise we might load Grape::API::Helpers
    helpers ::API::Helpers

    mount ::API::Groups
    mount ::API::GroupMembers
    mount ::API::Users
    mount ::API::Projects
    mount ::API::Repositories
    mount ::API::Issues
    mount ::API::Milestones
    mount ::API::Session
    mount ::API::MergeRequests
    mount ::API::Notes
    mount ::API::Internal
    mount ::API::SystemHooks
    mount ::API::ProjectSnippets
    mount ::API::ProjectMembers
    mount ::API::DeployKeys
    mount ::API::ProjectHooks
    mount ::API::Services
    mount ::API::Files
    mount ::API::Commits
    mount ::API::CommitStatuses
    mount ::API::Namespaces
    mount ::API::Branches
    mount ::API::Labels
    mount ::API::Settings
    mount ::API::Keys
    mount ::API::Tags
    mount ::API::Triggers
    mount ::API::Builds
    mount ::API::Variables
    mount ::API::Runners
    mount ::API::Licenses
N
Nihad Abbasov 已提交
60
  end
61
end