change raven syntax
This commit is contained in:
parent
185067265c
commit
1e04b52f5f
|
@ -1,15 +1,10 @@
|
||||||
|
# require 'raven'
|
||||||
# require 'sentry-raven'
|
|
||||||
|
|
||||||
module Travis::API::V3
|
module Travis::API::V3
|
||||||
class Router
|
class Router
|
||||||
include Travis::API::V3
|
include Travis::API::V3
|
||||||
attr_accessor :routes, :metrics_processor
|
attr_accessor :routes, :metrics_processor
|
||||||
|
|
||||||
# Raven.configure do |config|
|
|
||||||
# config.dsn = Travis.config.sentry.dsn
|
|
||||||
# end
|
|
||||||
|
|
||||||
def initialize(routes = Routes)
|
def initialize(routes = Routes)
|
||||||
@routes = routes
|
@routes = routes
|
||||||
@metrics_processor = Metrics::Processor.new
|
@metrics_processor = Metrics::Processor.new
|
||||||
|
@ -25,7 +20,6 @@ module Travis::API::V3
|
||||||
env_params = params(env)
|
env_params = params(env)
|
||||||
factory, params = routes.factory_for(env['REQUEST_METHOD'.freeze], env['PATH_INFO'.freeze])
|
factory, params = routes.factory_for(env['REQUEST_METHOD'.freeze], env['PATH_INFO'.freeze])
|
||||||
|
|
||||||
|
|
||||||
raise NotFound unless factory
|
raise NotFound unless factory
|
||||||
metrics.name_after(factory)
|
metrics.name_after(factory)
|
||||||
|
|
||||||
|
@ -43,8 +37,7 @@ module Travis::API::V3
|
||||||
metrics.success(status: response[0])
|
metrics.success(status: response[0])
|
||||||
response
|
response
|
||||||
rescue Error => error
|
rescue Error => error
|
||||||
Raven.capture do
|
Raven.capture_exception(error)
|
||||||
# 1 / 0
|
|
||||||
metrics.tick(:service)
|
metrics.tick(:service)
|
||||||
|
|
||||||
result = Result.new(access_control, :error, error)
|
result = Result.new(access_control, :error, error)
|
||||||
|
@ -55,7 +48,6 @@ module Travis::API::V3
|
||||||
|
|
||||||
response
|
response
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
def render(result, env_params, env)
|
def render(result, env_params, env)
|
||||||
V3.response(result.render(env_params, env), status: result.status)
|
V3.response(result.render(env_params, env), status: result.status)
|
||||||
|
|
|
@ -13,17 +13,30 @@ describe Travis::API::V3::ServiceIndex, set_app: true do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe Travis::API::V3::Router, set_app: true do
|
describe Travis::API::V3::Router, set_app: true do
|
||||||
|
class FixRaven < Struct.new(:app)
|
||||||
|
def call(env)
|
||||||
|
requested_at = env['requested_at']
|
||||||
|
env['requested_at'] = env['requested_at'].to_s if env.key?('requested_at')
|
||||||
|
app.call(env)
|
||||||
|
rescue Exception => e
|
||||||
|
env['requested_at'] = requested_at
|
||||||
|
raise e
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
class TestError < StandardError
|
class TestError < StandardError
|
||||||
end
|
end
|
||||||
|
|
||||||
before do
|
before do
|
||||||
|
set_app Raven::Rack.new(FixRaven.new(app))
|
||||||
Travis.config.sentry.dsn = "test"
|
Travis.config.sentry.dsn = "test"
|
||||||
|
Travis::Api::App.setup_monitoring
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'Sentry captures router errors' do
|
it 'Sentry captures router errors' do
|
||||||
error = TestError.new('Konstantin broke all the thingz!')
|
error = TestError.new('Konstantin broke all the thingz!')
|
||||||
Travis::API::V3::Models::Repository.any_instance.stubs(:service).raises(error)
|
Travis::API::V3::Models::Repository.any_instance.stubs(:service).raises(error)
|
||||||
Raven.expects(:capture).with do |event|
|
Raven.expects(:send_event).with do |event|
|
||||||
event.message == "#{error.class}: #{error.message}"
|
event.message == "#{error.class}: #{error.message}"
|
||||||
end
|
end
|
||||||
expect { get "/v3/repo/1" }.to raise_error(TestError)
|
expect { get "/v3/repo/1" }.to raise_error(TestError)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user