Commit e26a30e5 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Improve error message when `include` is blocked

parent 380f63bf
...@@ -31,14 +31,12 @@ module Gitlab ...@@ -31,14 +31,12 @@ module Gitlab
errors.push("Remote file `#{location}` could not be fetched because of a timeout error!") errors.push("Remote file `#{location}` could not be fetched because of a timeout error!")
rescue Gitlab::HTTP::Error rescue Gitlab::HTTP::Error
errors.push("Remote file `#{location}` could not be fetched because of HTTP error!") errors.push("Remote file `#{location}` could not be fetched because of HTTP error!")
rescue Gitlab::HTTP::BlockedUrlError rescue Gitlab::HTTP::BlockedUrlError => e
errors.push("Remote file `#{location}` could not be fetched because the URL is blocked!") errors.push("Remote file could not be fetched because #{e}!")
end end
if response&.code.to_i >= 400 if response&.code.to_i >= 400
errors.push <<~ERROR errors.push("Remote file `#{location}` could not be fetched because of HTTP code `#{response.code}` error!")
Remote file `#{location}` could not be fetched because of HTTP code `#{response.code}` error!
ERROR
end end
response.to_s if errors.none? response.to_s if errors.none?
......
...@@ -144,5 +144,14 @@ describe Gitlab::Ci::Config::External::File::Remote do ...@@ -144,5 +144,14 @@ describe Gitlab::Ci::Config::External::File::Remote do
expect(subject).to match /could not be fetched because of HTTP code `404` error!/ expect(subject).to match /could not be fetched because of HTTP code `404` error!/
end end
end end
context 'when the URL is blocked' do
let(:location) { 'http://127.0.0.1/some/path/to/config.yaml' }
it 'should include details about blocked URL' do
expect(subject).to eq "Remote file could not be fetched because URL '#{location}' " \
'is blocked: Requests to localhost are not allowed!'
end
end
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