From 10b2383f02c6726b6c07f78f3a3fcd2021e6f9f3 Mon Sep 17 00:00:00 2001 From: George Koltsov Date: Wed, 14 Aug 2019 12:07:42 +0100 Subject: Exclude json content type from workhorse interception --- app/controllers/application_controller.rb | 6 +++++- spec/controllers/application_controller_spec.rb | 28 ++++++++++++++++--------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 1d55a073f3b..3bb19e8628a 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -116,7 +116,7 @@ class ApplicationController < ActionController::Base def render(*args) super.tap do # Set a header for custom error pages to prevent them from being intercepted by gitlab-workhorse - if response.content_type == 'text/html' && (400..599).cover?(response.status) + if workhorse_excluded_content_types.include?(response.content_type) && (400..599).cover?(response.status) response.headers['X-GitLab-Custom-Error'] = '1' end end @@ -124,6 +124,10 @@ class ApplicationController < ActionController::Base protected + def workhorse_excluded_content_types + @workhorse_excluded_content_types ||= %w(text/html application/json) + end + def append_info_to_payload(payload) super diff --git a/spec/controllers/application_controller_spec.rb b/spec/controllers/application_controller_spec.rb index 84bbbac39b0..0b3833e6515 100644 --- a/spec/controllers/application_controller_spec.rb +++ b/spec/controllers/application_controller_spec.rb @@ -641,24 +641,32 @@ describe ApplicationController do end end - it 'does not set a custom header' do + it 'sets a custom header' do get :index, format: :json - expect(response.headers['X-GitLab-Custom-Error']).to be_nil + expect(response.headers['X-GitLab-Custom-Error']).to eq '1' end - end - context 'given a json response for an html request' do - controller do - def index - render json: {}, status: :unprocessable_entity + context 'for html request' do + it 'sets a custom header' do + get :index + + expect(response.headers['X-GitLab-Custom-Error']).to eq '1' end end - it 'does not set a custom header' do - get :index + context 'for 200 response' do + controller do + def index + render json: {}, status: :ok + end + end - expect(response.headers['X-GitLab-Custom-Error']).to be_nil + it 'does not set a custom header' do + get :index, format: :json + + expect(response.headers['X-GitLab-Custom-Error']).to be_nil + end end end end -- cgit v1.2.3 From 879bcaac2644a5e16190b8fa4a3776f1d93c3820 Mon Sep 17 00:00:00 2001 From: George Koltsov Date: Wed, 14 Aug 2019 12:25:44 +0100 Subject: Add changelog entry --- .../unreleased/georgekoltsov-48854-fix-empty-flash-message.yml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 changelogs/unreleased/georgekoltsov-48854-fix-empty-flash-message.yml diff --git a/changelogs/unreleased/georgekoltsov-48854-fix-empty-flash-message.yml b/changelogs/unreleased/georgekoltsov-48854-fix-empty-flash-message.yml new file mode 100644 index 00000000000..e28dbd6f0c4 --- /dev/null +++ b/changelogs/unreleased/georgekoltsov-48854-fix-empty-flash-message.yml @@ -0,0 +1,6 @@ +--- +title: Fix empty error flash message on profile:account page when updating username + with username that has already been taken +merge_request: 31809 +author: +type: fixed -- cgit v1.2.3 From 2857a40950d23173e4280513a5f318b89d1d0a11 Mon Sep 17 00:00:00 2001 From: George Koltsov Date: Thu, 15 Aug 2019 10:11:35 +0100 Subject: Swap clauses as per code review suggestion --- app/controllers/application_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 3bb19e8628a..5e65084a110 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -116,7 +116,7 @@ class ApplicationController < ActionController::Base def render(*args) super.tap do # Set a header for custom error pages to prevent them from being intercepted by gitlab-workhorse - if workhorse_excluded_content_types.include?(response.content_type) && (400..599).cover?(response.status) + if (400..599).cover?(response.status) && workhorse_excluded_content_types.include?(response.content_type) response.headers['X-GitLab-Custom-Error'] = '1' end end -- cgit v1.2.3