Skip to content

Commit 47e7572

Browse files
authored
Merge pull request duckdb#10 from Flogex/multipart-http-error
Throw HTTP error for status != 200 in InitializeMultipartUpload
2 parents d9d4ea6 + 980dc30 commit 47e7572

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

extension/httpfs/s3fs.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,13 +277,19 @@ string S3FileSystem::InitializeMultipartUpload(S3FileHandle &file_handle) {
277277
string query_param = "uploads=";
278278
auto res = s3fs.PostRequest(file_handle, file_handle.path, {}, response_buffer, response_buffer_len, nullptr, 0,
279279
query_param);
280+
281+
if (res->code != 200) {
282+
throw HTTPException(*res, "Unable to connect to URL %s: %s (HTTP code %s)", res->http_url, res->error,
283+
to_string(res->code));
284+
}
285+
280286
string result(response_buffer.get(), response_buffer_len);
281287

282288
auto open_tag_pos = result.find("<UploadId>", 0);
283289
auto close_tag_pos = result.find("</UploadId>", open_tag_pos);
284290

285291
if (open_tag_pos == string::npos || close_tag_pos == string::npos) {
286-
throw std::runtime_error("Unexpected response while initializing S3 multipart upload");
292+
throw HTTPException("Unexpected response while initializing S3 multipart upload");
287293
}
288294

289295
open_tag_pos += 10; // Skip open tag
@@ -315,7 +321,7 @@ void S3FileSystem::UploadBuffer(S3FileHandle &file_handle, shared_ptr<S3WriteBuf
315321
query_param);
316322

317323
if (res->code != 200) {
318-
throw HTTPException(*res, "Unable to connect to URL %s %s (HTTP code %s)", res->http_url, res->error,
324+
throw HTTPException(*res, "Unable to connect to URL %s: %s (HTTP code %s)", res->http_url, res->error,
319325
to_string(res->code));
320326
}
321327

0 commit comments

Comments
 (0)