MDL-36456 repository: S3 handles errors in a nicer way
This commit is contained in:
@@ -100,6 +100,7 @@ $string['error'] = 'An unknown error occurred!';
|
||||
$string['errornotyourfile'] = 'You cannot pick file which is not added by your';
|
||||
$string['erroruniquename'] = 'Repository instance name should be unique';
|
||||
$string['errorpostmaxsize'] = 'The uploaded file may exceed max_post_size directive in php.ini.';
|
||||
$string['errorwhilecommunicatingwith'] = 'Error while communicating with the repository \'{$a}\'.';
|
||||
$string['errorwhiledownload'] = 'An error occured while downloading the file: {$a}';
|
||||
$string['existingrepository'] = 'This repository already exists';
|
||||
$string['federatedsearch'] = 'Federated search';
|
||||
|
||||
+17
-4
@@ -47,6 +47,7 @@ class repository_s3 extends repository {
|
||||
$this->access_key = get_config('s3', 'access_key');
|
||||
$this->secret_key = get_config('s3', 'secret_key');
|
||||
$this->s = new S3($this->access_key, $this->secret_key);
|
||||
$this->s->setExceptions(true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -75,7 +76,7 @@ class repository_s3 extends repository {
|
||||
public function get_listing($path = '', $page = '') {
|
||||
global $CFG, $OUTPUT;
|
||||
if (empty($this->access_key)) {
|
||||
die(json_encode(array('e'=>get_string('needaccesskey', 'repository_s3'))));
|
||||
throw new moodle_exception('needaccesskey', 'repository_s3');
|
||||
}
|
||||
|
||||
$list = array();
|
||||
@@ -97,7 +98,11 @@ class repository_s3 extends repository {
|
||||
$tree = array();
|
||||
|
||||
if (empty($path)) {
|
||||
$buckets = $this->s->listBuckets();
|
||||
try {
|
||||
$buckets = $this->s->listBuckets();
|
||||
} catch (S3Exception $e) {
|
||||
throw new moodle_exception('errorwhilecommunicatingwith', 'repository', '', $this->get_name());
|
||||
}
|
||||
foreach ($buckets as $bucket) {
|
||||
$folder = array(
|
||||
'title' => $bucket,
|
||||
@@ -112,7 +117,11 @@ class repository_s3 extends repository {
|
||||
$folders = array();
|
||||
list($bucket, $uri) = $this->explode_path($path);
|
||||
|
||||
$contents = $this->s->getBucket($bucket, $uri, null, null, '/', true);
|
||||
try {
|
||||
$contents = $this->s->getBucket($bucket, $uri, null, null, '/', true);
|
||||
} catch (S3Exception $e) {
|
||||
throw new moodle_exception('errorwhilecommunicatingwith', 'repository', '', $this->get_name());
|
||||
}
|
||||
foreach ($contents as $object) {
|
||||
|
||||
// If object has a prefix, it is a 'CommonPrefix', which we consider a folder
|
||||
@@ -183,7 +192,11 @@ class repository_s3 extends repository {
|
||||
public function get_file($filepath, $file = '') {
|
||||
list($bucket, $uri) = $this->explode_path($filepath);
|
||||
$path = $this->prepare_file($file);
|
||||
$this->s->getObject($bucket, $uri, $path);
|
||||
try {
|
||||
$this->s->getObject($bucket, $uri, $path);
|
||||
} catch (S3Exception $e) {
|
||||
throw new moodle_exception('errorwhilecommunicatingwith', 'repository', '', $this->get_name());
|
||||
}
|
||||
return array('path' => $path);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user