Skip to content

Commit 1a95fcc

Browse files
author
michaelkotlyar
committed
Attempt to read object before creating it.
1 parent 40f466b commit 1a95fcc

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

classes/local/store/swift/client.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -203,12 +203,22 @@ public function test_connection() {
203203
}
204204

205205
try {
206-
$container->createObject(['name' => 'connection_check_file', 'content' => 'connection_check_file']);
206+
$container->getObject('connection_check_file')->download();
207207
} catch (\OpenStack\Common\Error\BadResponseError $e) {
208-
$connection->success = false;
209-
$connection->details = $this->get_exception_details($e);
210-
} catch (\Exception $e) {
211-
$connection->success = false;
208+
if ($e->getResponse()->getStatusCode() == 404) {
209+
try {
210+
$container->createObject(['name' => 'connection_check_file', 'content' => 'connection_check_file']);
211+
} catch (\OpenStack\Common\Error\BadResponseError $e) {
212+
$connection->success = false;
213+
$connection->details = $this->get_exception_details($e);
214+
} catch (\Exception $e) {
215+
$connection->success = false;
216+
}
217+
} else {
218+
$details = $this->get_exception_details($e);
219+
$connection->messages[get_string('settings:readfailure', 'tool_objectfs') . $details] = 'notifyproblem';
220+
$connection->success = false;
221+
}
212222
}
213223

214224
return $connection;

0 commit comments

Comments
 (0)