Skip to content
Snippets Groups Projects
Verified Commit 4e1acedb authored by Stan Hu's avatar Stan Hu
Browse files

Add HTTP status to LFS push client error messages

Currently if a remote mirror update fails to push LFS objects, it's hard
to diagnose what went wrong. We now add the HTTP status code (e.g. 401
Unauthorized) to provide more detail.

Relates to #340482

Changelog: added
parent 77e6ac79
No related branches found
No related tags found
1 merge request!77334Add HTTP status to LFS push client error messages
......@@ -36,7 +36,7 @@ def batch!(operation, objects)
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
# application/json content type in the response, which we can't rely on
......@@ -65,7 +65,7 @@ def upload!(object, upload_action, authenticated:)
rsp = Gitlab::HTTP.put(upload_action['href'], params)
raise ObjectUploadError unless rsp.success?
raise ObjectUploadError.new(http_response: rsp) unless rsp.success?
ensure
file&.close
end
......@@ -81,7 +81,7 @@ def verify!(object, verify_action, authenticated:)
rsp = Gitlab::HTTP.post(verify_action['href'], params)
raise ObjectVerifyError unless rsp.success?
raise ObjectVerifyError.new(http_response: rsp) unless rsp.success?
end
private
......@@ -105,9 +105,21 @@ def basic_auth
{ username: credentials[:user], password: credentials[:password] }
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
"Failed to submit batch"
"Failed to submit batch: #{http_error}"
end
end
......@@ -122,15 +134,15 @@ def message
end
end
class ObjectUploadError < StandardError
class ObjectUploadError < HttpError
def message
"Failed to upload object"
"Failed to upload object: #{http_error}"
end
end
class ObjectVerifyError < StandardError
class ObjectVerifyError < HttpError
def message
"Failed to verify object"
"Failed to verify object: #{http_error}"
end
end
end
......
......@@ -159,7 +159,7 @@ def stub_batch(objects:, headers:, operation: 'upload', transfer: 'basic')
it 'raises an error' do
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
......@@ -167,7 +167,7 @@ def stub_batch(objects:, headers:, operation: 'upload', transfer: 'basic')
it 'raises an error' do
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
......@@ -226,7 +226,7 @@ def stub_upload(object:, headers:)
it 'raises an error' do
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
......@@ -234,7 +234,7 @@ def stub_upload(object:, headers:)
it 'raises an error' do
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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment