Commit 946e0078 authored by Alper Akgun's avatar Alper Akgun

Merge branch 'sh-add-http-status-lfs-push-service' into 'master'

Add HTTP status to LFS push client error messages

See merge request gitlab-org/gitlab!77334
parents 549f5a74 4e1acedb
...@@ -36,7 +36,7 @@ module Gitlab ...@@ -36,7 +36,7 @@ module Gitlab
headers: build_request_headers headers: build_request_headers
) )
raise BatchSubmitError unless rsp.success? raise BatchSubmitError.new(http_response: rsp) unless rsp.success?
# HTTParty provides rsp.parsed_response, but it only kicks in for the # HTTParty provides rsp.parsed_response, but it only kicks in for the
# application/json content type in the response, which we can't rely on # application/json content type in the response, which we can't rely on
...@@ -65,7 +65,7 @@ module Gitlab ...@@ -65,7 +65,7 @@ module Gitlab
rsp = Gitlab::HTTP.put(upload_action['href'], params) rsp = Gitlab::HTTP.put(upload_action['href'], params)
raise ObjectUploadError unless rsp.success? raise ObjectUploadError.new(http_response: rsp) unless rsp.success?
ensure ensure
file&.close file&.close
end end
...@@ -81,7 +81,7 @@ module Gitlab ...@@ -81,7 +81,7 @@ module Gitlab
rsp = Gitlab::HTTP.post(verify_action['href'], params) rsp = Gitlab::HTTP.post(verify_action['href'], params)
raise ObjectVerifyError unless rsp.success? raise ObjectVerifyError.new(http_response: rsp) unless rsp.success?
end end
private private
...@@ -105,9 +105,21 @@ module Gitlab ...@@ -105,9 +105,21 @@ module Gitlab
{ username: credentials[:user], password: credentials[:password] } { username: credentials[:user], password: credentials[:password] }
end end
class BatchSubmitError < StandardError class HttpError < StandardError
def initialize(http_response:)
super
@http_response = http_response
end
def http_error
"HTTP status #{@http_response.code}"
end
end
class BatchSubmitError < HttpError
def message def message
"Failed to submit batch" "Failed to submit batch: #{http_error}"
end end
end end
...@@ -122,15 +134,15 @@ module Gitlab ...@@ -122,15 +134,15 @@ module Gitlab
end end
end end
class ObjectUploadError < StandardError class ObjectUploadError < HttpError
def message def message
"Failed to upload object" "Failed to upload object: #{http_error}"
end end
end end
class ObjectVerifyError < StandardError class ObjectVerifyError < HttpError
def message def message
"Failed to verify object" "Failed to verify object: #{http_error}"
end end
end end
end end
......
...@@ -159,7 +159,7 @@ RSpec.describe Gitlab::Lfs::Client do ...@@ -159,7 +159,7 @@ RSpec.describe Gitlab::Lfs::Client do
it 'raises an error' do it 'raises an error' do
stub_upload(object: object, headers: upload_action['header']).to_return(status: 400) stub_upload(object: object, headers: upload_action['header']).to_return(status: 400)
expect { lfs_client.upload!(object, upload_action, authenticated: true) }.to raise_error(/Failed/) expect { lfs_client.upload!(object, upload_action, authenticated: true) }.to raise_error(/Failed to upload object: HTTP status 400/)
end end
end end
...@@ -167,7 +167,7 @@ RSpec.describe Gitlab::Lfs::Client do ...@@ -167,7 +167,7 @@ RSpec.describe Gitlab::Lfs::Client do
it 'raises an error' do it 'raises an error' do
stub_upload(object: object, headers: upload_action['header']).to_return(status: 500) stub_upload(object: object, headers: upload_action['header']).to_return(status: 500)
expect { lfs_client.upload!(object, upload_action, authenticated: true) }.to raise_error(/Failed/) expect { lfs_client.upload!(object, upload_action, authenticated: true) }.to raise_error(/Failed to upload object: HTTP status 500/)
end end
end end
...@@ -226,7 +226,7 @@ RSpec.describe Gitlab::Lfs::Client do ...@@ -226,7 +226,7 @@ RSpec.describe Gitlab::Lfs::Client do
it 'raises an error' do it 'raises an error' do
stub_verify(object: object, headers: verify_action['header']).to_return(status: 400) stub_verify(object: object, headers: verify_action['header']).to_return(status: 400)
expect { lfs_client.verify!(object, verify_action, authenticated: true) }.to raise_error(/Failed/) expect { lfs_client.verify!(object, verify_action, authenticated: true) }.to raise_error(/Failed to verify object: HTTP status 400/)
end end
end end
...@@ -234,7 +234,7 @@ RSpec.describe Gitlab::Lfs::Client do ...@@ -234,7 +234,7 @@ RSpec.describe Gitlab::Lfs::Client do
it 'raises an error' do it 'raises an error' do
stub_verify(object: object, headers: verify_action['header']).to_return(status: 500) stub_verify(object: object, headers: verify_action['header']).to_return(status: 500)
expect { lfs_client.verify!(object, verify_action, authenticated: true) }.to raise_error(/Failed/) expect { lfs_client.verify!(object, verify_action, authenticated: true) }.to raise_error(/Failed to verify object: HTTP status 500/)
end end
end end
......
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