Commit 9d5560d4 authored by Peter Leitzen's avatar Peter Leitzen

Merge branch 'fj-add-logging-to-snippet-services' into 'master'

Add logging to snippet create/update services

See merge request gitlab-org/gitlab!27795
parents 56f2dd54 53477a58
......@@ -50,6 +50,7 @@ module Snippets
snippet_saved
rescue => e # Rescuing all because we can receive Creation exceptions, GRPC exceptions, Git exceptions, ...
snippet.errors.add(:base, e.message)
log_error(e.message)
# If the commit action failed we need to remove the repository if exists
snippet.repository.remove if snippet.repository_exists?
......
......@@ -51,8 +51,9 @@ module Snippets
# the changes
create_commit(snippet) if snippet.repository_exists?
end
rescue
rescue => e
snippet.errors.add(:repository, 'Error updating the snippet')
log_error(e.message)
false
end
......
......@@ -199,6 +199,12 @@ describe Snippets::CreateService do
expect(SnippetRepository.count).to be_zero
end
it 'logs the error' do
expect(Gitlab::AppLogger).to receive(:error).with('foobar')
subject
end
it 'returns the error' do
response = subject
......
......@@ -167,13 +167,23 @@ describe Snippets::UpdateService do
expect(blob.data).to eq(options[:content])
end
it 'returns error when the commit action fails' do
allow(snippet.snippet_repository).to receive(:multi_files_action).and_raise(SnippetRepository::CommitError)
context 'when an error is raised' do
before do
allow(snippet.snippet_repository).to receive(:multi_files_action).and_raise(SnippetRepository::CommitError, 'foobar')
end
response = subject
it 'logs the error' do
expect(Gitlab::AppLogger).to receive(:error).with('foobar')
expect(response).to be_error
expect(response.payload[:snippet].errors.full_messages).to eq ['Repository Error updating the snippet']
subject
end
it 'returns error with generic error message' do
response = subject
expect(response).to be_error
expect(response.payload[:snippet].errors.full_messages).to eq ['Repository Error updating the snippet']
end
end
it 'returns error if snippet does not have a snippet_repository' do
......
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