fix(AmazonS3): pass S3 error messages through to the frontend

* S3Exception to NotPermittedException in Storage/AmazonS3::writeStream()
* NotPermittedException to Forbidden in Storage/Common::copyFromStorage()

Improves error messages on move/copy operations when bucket quota exceeded

Fixes: #58801

Signed-off-by: Jonas <jonas@freesources.org>
pull/62163/head
Jonas 4 months ago
parent ba019518a4
commit cebcc6cc01
No known key found for this signature in database
GPG Key ID: 5262E7FF491049FE
  1. 11
      apps/files_external/lib/Lib/Storage/AmazonS3.php
  2. 4
      lib/private/Files/Storage/Common.php

@ -20,6 +20,7 @@ use OCP\Cache\CappedMemoryCache;
use OCP\Constants;
use OCP\Files\FileInfo;
use OCP\Files\IMimeTypeDetector;
use OCP\Files\NotPermittedException;
use OCP\ICache;
use OCP\ICacheFactory;
use OCP\ITempManager;
@ -772,7 +773,15 @@ class AmazonS3 extends Common {
}
$path = $this->normalizePath($path);
$this->writeObject($path, $stream, $this->mimeDetector->detectPath($path));
try {
$this->writeObject($path, $stream, $this->mimeDetector->detectPath($path));
} catch (S3Exception $exception) {
$this->logger->error($exception->getMessage(), [
'app' => 'files_external',
'exception' => $exception,
]);
throw new NotPermittedException($exception->getMessage(), $exception->getCode(), $exception);
}
$this->invalidateCache($path);
return $size;

@ -32,6 +32,7 @@ use OCP\Files\GenericFileException;
use OCP\Files\IFilenameValidator;
use OCP\Files\IMimeTypeDetector;
use OCP\Files\InvalidPathException;
use OCP\Files\NotPermittedException;
use OCP\Files\Storage\IConstructableStorage;
use OCP\Files\Storage\ILockingStorage;
use OCP\Files\Storage\IStorage;
@ -562,6 +563,9 @@ abstract class Common implements Storage, ILockingStorage, IWriteStreamStorage,
try {
$this->writeStream($targetInternalPath, $source);
$result = true;
} catch (NotPermittedException $e) {
Server::get(LoggerInterface::class)->warning('Failed to copy stream to storage', ['exception' => $e]);
throw new ForbiddenException($e->getMessage(), false, $e);
} catch (\Exception $e) {
Server::get(LoggerInterface::class)->warning('Failed to copy stream to storage', ['exception' => $e]);
}

Loading…
Cancel
Save