Commit 63dbf730 authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch 'handle_changelog_exception' into 'master'

Return a 422 error for Changelog::Error exception

See merge request gitlab-org/gitlab!80850
parents 62a8184f 896a7c1d
...@@ -248,6 +248,8 @@ module API ...@@ -248,6 +248,8 @@ module API
changelog = service.execute(commit_to_changelog: false) changelog = service.execute(commit_to_changelog: false)
present changelog, with: Entities::Changelog present changelog, with: Entities::Changelog
rescue Gitlab::Changelog::Error => ex
render_api_error!("Failed to generate the changelog: #{ex.message}", 422)
end end
desc 'Generates a changelog section for a release and commits it in a changelog file' do desc 'Generates a changelog section for a release and commits it in a changelog file' do
......
...@@ -783,6 +783,13 @@ RSpec.describe API::Repositories do ...@@ -783,6 +783,13 @@ RSpec.describe API::Repositories do
expect(response).to have_gitlab_http_status(:ok) expect(response).to have_gitlab_http_status(:ok)
expect(json_response['notes']).to be_present expect(json_response['notes']).to be_present
end end
context 'when previous tag version does not exist' do
it_behaves_like '422 response' do
let(:request) { get api("/projects/#{project.id}/repository/changelog", user), params: { version: 'v0.0.0' } }
let(:message) { 'Failed to generate the changelog: The commit start range is unspecified, and no previous tag could be found to use instead' }
end
end
end end
describe 'POST /projects/:id/repository/changelog' do describe 'POST /projects/:id/repository/changelog' 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