From ee8942c62bfd8a93815c531e9a2dc32e83c175f5 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 20 Nov 2023 17:30:04 +0100 Subject: [PATCH] raise proper error when s3 object doesn't exist Signed-off-by: Robin Appelman --- lib/private/Files/ObjectStore/S3ObjectTrait.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/private/Files/ObjectStore/S3ObjectTrait.php b/lib/private/Files/ObjectStore/S3ObjectTrait.php index 4d6ac3608df08..55626be42c571 100644 --- a/lib/private/Files/ObjectStore/S3ObjectTrait.php +++ b/lib/private/Files/ObjectStore/S3ObjectTrait.php @@ -33,6 +33,7 @@ use Aws\S3\S3Client; use Icewind\Streams\CallbackWrapper; use OC\Files\Stream\SeekableHttpStream; +use OCP\Files\NotFoundException; trait S3ObjectTrait { /** @@ -71,7 +72,11 @@ public function readObject($urn) { ]; $context = stream_context_create($opts); - return fopen($request->getUri(), 'r', false, $context); + $fh = fopen($request->getUri(), 'r', false, $context); + if (!$fh && isset($http_response_header[0]) && str_contains($http_response_header[0], '404')) { + throw new NotFoundException("object $urn not found in object store bucket " . $this->getBucket()); + } + return $fh; }); }