Commit b5bcf80c authored by Luke Duncalfe's avatar Luke Duncalfe

Update service to handle unexpected exceptions

This will ensure that now and in the future, PushOptionsHandlerService
will not cause the post_receive API endpoint from running other code if
something causes an unknown exception.
parent 3c40c98e
......@@ -24,6 +24,9 @@ module MergeRequests
execute_for_branch(branch)
rescue Gitlab::Access::AccessDeniedError
errors << 'User access was denied'
rescue StandardError => e
Gitlab::AppLogger.error(e)
errors << 'An unknown error occurred'
end
self
......
......@@ -334,6 +334,32 @@ describe MergeRequests::PushOptionsHandlerService do
end
end
describe 'handling unexpected exceptions' do
let(:push_options) { { create: true } }
let(:changes) { new_branch_changes }
let(:exception) { StandardError.new('My standard error') }
def run_service_with_exception
allow_any_instance_of(
MergeRequests::BuildService
).to receive(:execute).and_raise(exception)
service.execute
end
it 'records an error' do
run_service_with_exception
expect(service.errors).to eq(['An unknown error occurred'])
end
it 'writes to Gitlab::AppLogger' do
expect(Gitlab::AppLogger).to receive(:error).with(exception)
run_service_with_exception
end
end
describe 'when target is not a valid branch name' do
let(:push_options) { { create: true, target: 'my-branch' } }
let(:changes) { new_branch_changes }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment