Commit 924a228c authored by Matt Kasa's avatar Matt Kasa

Return client error for duplicate Terraform state serials

Changelog: fixed

Fixes https://gitlab.com/gitlab-org/gitlab/-/issues/344085
parent 97d03fa2
...@@ -11,6 +11,13 @@ module API ...@@ -11,6 +11,13 @@ module API
default_format :json default_format :json
rescue_from(
::ActiveRecord::RecordNotUnique,
::PG::UniqueViolation
) do |e|
render_api_error!(e.message, 422)
end
before do before do
authenticate! authenticate!
authorize! :read_terraform_state, user_project authorize! :read_terraform_state, user_project
......
...@@ -152,6 +152,16 @@ RSpec.describe API::Terraform::State do ...@@ -152,6 +152,16 @@ RSpec.describe API::Terraform::State do
expect(response).to have_gitlab_http_status(:ok) expect(response).to have_gitlab_http_status(:ok)
expect(Gitlab::Json.parse(response.body)).to be_empty expect(Gitlab::Json.parse(response.body)).to be_empty
end end
context 'when serial already exists' do
let(:params) { { 'instance': 'example-instance', 'serial': state.latest_version.version } }
it 'returns unprocessable entity' do
request
expect(response).to have_gitlab_http_status(:unprocessable_entity)
end
end
end end
context 'without body' do context 'without body' 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