Skip to content

Commit 5472494

Browse files
committed
Wrap S3 multipart upload exception
Signed-off-by: Louis Chemineau <louis@chmn.me>
1 parent 0b768c1 commit 5472494

File tree

5 files changed

+48
-1
lines changed

5 files changed

+48
-1
lines changed

apps/dav/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@
151151
'OCA\\DAV\\Connector\\Sabre\\Directory' => $baseDir . '/../lib/Connector/Sabre/Directory.php',
152152
'OCA\\DAV\\Connector\\Sabre\\DummyGetResponsePlugin' => $baseDir . '/../lib/Connector/Sabre/DummyGetResponsePlugin.php',
153153
'OCA\\DAV\\Connector\\Sabre\\ExceptionLoggerPlugin' => $baseDir . '/../lib/Connector/Sabre/ExceptionLoggerPlugin.php',
154+
'OCA\\DAV\\Connector\\Sabre\\Exception\\BadGateway' => $baseDir . '/../lib/Connector/Sabre/Exception/BadGateway.php',
154155
'OCA\\DAV\\Connector\\Sabre\\Exception\\EntityTooLarge' => $baseDir . '/../lib/Connector/Sabre/Exception/EntityTooLarge.php',
155156
'OCA\\DAV\\Connector\\Sabre\\Exception\\FileLocked' => $baseDir . '/../lib/Connector/Sabre/Exception/FileLocked.php',
156157
'OCA\\DAV\\Connector\\Sabre\\Exception\\Forbidden' => $baseDir . '/../lib/Connector/Sabre/Exception/Forbidden.php',

apps/dav/composer/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ class ComposerStaticInitDAV
166166
'OCA\\DAV\\Connector\\Sabre\\Directory' => __DIR__ . '/..' . '/../lib/Connector/Sabre/Directory.php',
167167
'OCA\\DAV\\Connector\\Sabre\\DummyGetResponsePlugin' => __DIR__ . '/..' . '/../lib/Connector/Sabre/DummyGetResponsePlugin.php',
168168
'OCA\\DAV\\Connector\\Sabre\\ExceptionLoggerPlugin' => __DIR__ . '/..' . '/../lib/Connector/Sabre/ExceptionLoggerPlugin.php',
169+
'OCA\\DAV\\Connector\\Sabre\\Exception\\BadGateway' => __DIR__ . '/..' . '/../lib/Connector/Sabre/Exception/BadGateway.php',
169170
'OCA\\DAV\\Connector\\Sabre\\Exception\\EntityTooLarge' => __DIR__ . '/..' . '/../lib/Connector/Sabre/Exception/EntityTooLarge.php',
170171
'OCA\\DAV\\Connector\\Sabre\\Exception\\FileLocked' => __DIR__ . '/..' . '/../lib/Connector/Sabre/Exception/FileLocked.php',
171172
'OCA\\DAV\\Connector\\Sabre\\Exception\\Forbidden' => __DIR__ . '/..' . '/../lib/Connector/Sabre/Exception/Forbidden.php',
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
/**
3+
* @copyright Copyright (c) 2016, ownCloud, Inc.
4+
*
5+
* @author Morris Jobke <hey@morrisjobke.de>
6+
* @author Thomas Müller <thomas.mueller@tmit.eu>
7+
* @author Vincent Petry <vincent@nextcloud.com>
8+
*
9+
* @license AGPL-3.0
10+
*
11+
* This code is free software: you can redistribute it and/or modify
12+
* it under the terms of the GNU Affero General Public License, version 3,
13+
* as published by the Free Software Foundation.
14+
*
15+
* This program is distributed in the hope that it will be useful,
16+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
* GNU Affero General Public License for more details.
19+
*
20+
* You should have received a copy of the GNU Affero General Public License, version 3,
21+
* along with this program. If not, see <http://www.gnu.org/licenses/>
22+
*
23+
*/
24+
namespace OCA\DAV\Connector\Sabre\Exception;
25+
26+
/**
27+
* Bad Gateway
28+
*
29+
* This exception is thrown whenever the server, while acting as a gateway or proxy, received an invalid response from the upstream server.
30+
*
31+
*/
32+
class BadGateway extends \Sabre\DAV\Exception {
33+
34+
/**
35+
* Returns the HTTP status code for this exception
36+
*
37+
* @return int
38+
*/
39+
public function getHTTPCode() {
40+
return 502;
41+
}
42+
}

apps/dav/lib/Connector/Sabre/File.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
use OCA\DAV\Connector\Sabre\Exception\FileLocked;
4848
use OCA\DAV\Connector\Sabre\Exception\Forbidden as DAVForbiddenException;
4949
use OCA\DAV\Connector\Sabre\Exception\UnsupportedMediaType;
50+
use OCA\DAV\Connector\Sabre\Exception\BadGateway;
5051
use OCP\Encryption\Exceptions\GenericEncryptionException;
5152
use OCP\Files\EntityTooLargeException;
5253
use OCP\Files\FileInfo;
@@ -206,6 +207,8 @@ public function put($data) {
206207
$count = $partStorage->writeStream($internalPartPath, $wrappedData);
207208
} catch (GenericFileException $e) {
208209
$result = false;
210+
} catch (BadGateway $e) {
211+
throw $e;
209212
}
210213

211214

lib/private/Files/ObjectStore/S3ObjectTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ protected function writeMultiPart(string $urn, StreamInterface $stream, string $
126126
if ($e->getState()->isInitiated() && (array_key_exists('UploadId', $uploadInfo))) {
127127
$this->getConnection()->abortMultipartUpload($uploadInfo);
128128
}
129-
throw new \OCP\Files\StorageConnectionException("Error while upload to S3 bucket", $e);
129+
throw new \OCA\DAV\Connector\Sabre\Exception\BadGateway("Error while upload to S3 bucket", 0, $e);
130130
}
131131
}
132132

0 commit comments

Comments
 (0)