diff --git a/CHANGELOG.md b/CHANGELOG.md index bccd6230b..ee95c0fc9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,8 @@ - Performance optimizations in `virtualbox` gem. Huge speed gains. - `:chef_server` provisioner is now `:chef_client`. [GH-359] - SUSE host only networking support. [GH-369] + - Show nice error message for invalid HTTP responses for HTTP + downloader. [GH-403] ## 0.7.6 (July 2, 2011) diff --git a/lib/vagrant/downloaders/http.rb b/lib/vagrant/downloaders/http.rb index 0cd042fec..bda8e9c0a 100644 --- a/lib/vagrant/downloaders/http.rb +++ b/lib/vagrant/downloaders/http.rb @@ -33,6 +33,8 @@ module Vagrant # TODO: Error on some redirect limit download!(response["Location"], destination_file) return + elsif !response.is_a?(Net::HTTPOK) + raise Errors::DownloaderHTTPStatusError, :status => response.code end total = response.content_length diff --git a/lib/vagrant/errors.rb b/lib/vagrant/errors.rb index cf3aa13b3..3d28a3a1a 100644 --- a/lib/vagrant/errors.rb +++ b/lib/vagrant/errors.rb @@ -148,6 +148,11 @@ module Vagrant error_key(:socket_error, "vagrant.downloaders.http") end + class DownloaderHTTPStatusError < VagrantError + status_code(51) + error_key(:status_error, "vagrant.downloaders.http") + end + class ForwardPortAutolistEmpty < VagrantError status_code(27) error_key(:auto_empty, "vagrant.actions.vm.forward_ports") diff --git a/templates/locales/en.yml b/templates/locales/en.yml index 23b81ec78..3beff04ac 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -448,6 +448,11 @@ en: An error occurred while trying to download the specified box. This most often happens if there is no internet connection or the address is invalid. + status_error: |- + Bad status code: %{status} + + Please verify that the box exists and is accessible. Also verify that + this computer is properly connected to the internet. hosts: bsd: diff --git a/test/vagrant/downloaders/http_test.rb b/test/vagrant/downloaders/http_test.rb index 65ee9d219..6d4ba3a98 100644 --- a/test/vagrant/downloaders/http_test.rb +++ b/test/vagrant/downloaders/http_test.rb @@ -42,6 +42,8 @@ class HttpDownloaderTest < Test::Unit::TestCase h = mock("http") response = mock("response") response.stubs(:content_length) + response.stubs(:is_a?).with(anything).returns(false) + response.stubs(:is_a?).with(Net::HTTPOK).returns(true) segment = mock("segment") segment.stubs(:length).returns(7)