Commit a104a6da authored by charlieablett's avatar charlieablett

Change SpamVerdictService GET to POST

- Add error logging if any HTTP errors occur
parent e63e567b
......@@ -41,10 +41,10 @@ module Spam
return unless Gitlab::CurrentSettings.spam_check_endpoint_enabled
return if endpoint_url.blank?
result = Gitlab::HTTP.try_get(endpoint_url, verdict_params)
return unless result
begin
result = Gitlab::HTTP.post(endpoint_url, body: verdict_params.to_json, headers: { 'Content-Type' => 'application/json' })
return unless result
json_result = Gitlab::Json.parse(result).with_indifferent_access
# @TODO metrics/logging
# Expecting:
......@@ -56,6 +56,10 @@ module Spam
# @TODO log if json_result[:error]
json_result[:verdict]
rescue *Gitlab::HTTP::HTTP_ERRORS => e
# @TODO: log error via try_post https://gitlab.com/gitlab-org/gitlab/-/issues/219223
Gitlab::ErrorTracking.log_exception(e)
return
rescue
# @TODO log
ALLOW
......
......@@ -169,7 +169,7 @@ describe Spam::SpamVerdictService do
before do
stub_application_setting(spam_check_endpoint_enabled: true)
stub_application_setting(spam_check_endpoint_url: "http://www.spamcheckurl.com/spam_check")
stub_request(:any, /.*spamcheckurl.com.*/).to_return( body: spam_check_body.to_json, status: spam_check_http_status )
stub_request(:post, /.*spamcheckurl.com.*/).to_return( body: spam_check_body.to_json, status: spam_check_http_status )
end
context 'if the endpoint is accessible' do
......@@ -248,7 +248,7 @@ describe Spam::SpamVerdictService do
context 'if the endpoint times out' do
before do
stub_request(:any, /.*spamcheckurl.com.*/).to_timeout
stub_request(:post, /.*spamcheckurl.com.*/).to_timeout
end
it 'returns nil' 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