diff --git a/eodag/plugins/download/http.py b/eodag/plugins/download/http.py index c46cad1b9..64b655054 100644 --- a/eodag/plugins/download/http.py +++ b/eodag/plugins/download/http.py @@ -772,13 +772,17 @@ def _stream_download_dict( ) else: + # get first chunk to check if it does not contain an error (if it does, that error will be raised) + first_chunks_tuple = next(chunks_tuples) outputs_filename = ( sanitize(product.properties["title"]) if "title" in product.properties else sanitize(product.properties.get("id", "download")) ) return StreamResponse( - content=stream_zip(chunks_tuples), + content=stream_zip( + chain(iter([first_chunks_tuple]), chunks_tuples) + ), media_type="application/zip", headers={ "content-disposition": f"attachment; filename={outputs_filename}.zip", diff --git a/tests/units/test_download_plugins.py b/tests/units/test_download_plugins.py index 274781bb2..fc97814f7 100644 --- a/tests/units/test_download_plugins.py +++ b/tests/units/test_download_plugins.py @@ -719,6 +719,38 @@ def test_plugins_download_http_assets_interrupt( ) ) + @mock.patch( + "eodag.plugins.download.http.ProgressCallback.__call__", + autospec=True, + ) + @mock.patch("eodag.plugins.download.http.requests.head", autospec=True) + @mock.patch("eodag.plugins.download.http.requests.get", autospec=True) + def test_plugins_download_http_assets_stream_zip_interrupt( + self, mock_requests_get, mock_requests_head, mock_progress_callback + ): + """HTTPDownload._stream_download_dict() must raise an error if an error is returned by the provider""" + + plugin = self.get_download_plugin(self.product) + self.product.location = self.product.remote_location = "http://somewhere" + self.product.properties["id"] = "someproduct" + self.product.assets.clear() + self.product.assets.update({"foo": {"href": "http://somewhere/something"}}) + self.product.assets.update({"any": {"href": "http://somewhere/anything"}}) + + # first asset returns error + mock_requests_get.return_value = MockResponse(status_code=404) + mock_requests_head.return_value.headers = { + "content-disposition": "", + "Content-length": "10", + } + + with self.assertRaises(DownloadError): + plugin._stream_download_dict(self.product, output_dir=self.output_dir) + # Interrupted download + # Product location not changed + self.assertEqual(self.product.location, "http://somewhere") + self.assertEqual(self.product.remote_location, "http://somewhere") + @mock.patch("eodag.plugins.download.http.requests.head", autospec=True) @mock.patch("eodag.plugins.download.http.requests.get", autospec=True) def test_plugins_download_http_assets_resume(