Skip to content
This repository has been archived by the owner on Jul 23, 2020. It is now read-only.

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
timmyomahony committed Jan 25, 2020
2 parents d1f44d2 + 6e4d87d commit 2fbb0bb
Showing 1 changed file with 29 additions and 13 deletions.
42 changes: 29 additions & 13 deletions src/services/providers/S3Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@


class S3Service extends SyncService implements Syncable {

/**
* Pull database backups from cloud to local backup folder
*
Expand All @@ -24,9 +23,8 @@ class S3Service extends SyncService implements Syncable {
public function pullDatabase(): bool {
try {
return $this->pull("sql");
} catch (AwsException $e) {
Craft::$app->getErrorHandler()->logException($e);
throw new ProviderException("AWS Error (Code: '" . $e->getAWSErrorCode() . "')");
} catch (AwsException $exception) {
throw new ProviderException($this->createErrorMessage($exception));
}
}

Expand All @@ -38,9 +36,8 @@ public function pullDatabase(): bool {
public function pushDatabase(): bool {
try {
return $this->push("sql");
} catch (AwsException $e) {
Craft::$app->getErrorHandler()->logException($e);
throw new ProviderException("AWS Error (Code: '" . $e->getAWSErrorCode() . "')");
} catch (AwsException $exception) {
throw new ProviderException($this->createErrorMessage($exception));
}
}

Expand All @@ -52,9 +49,8 @@ public function pushDatabase(): bool {
public function pullVolumes(): bool {
try {
return $this->pull("zip");
} catch (AwsException $e) {
Craft::$app->getErrorHandler()->logException($e);
throw new ProviderException("AWS Error (Code: '" . $e->getAWSErrorCode() . "')");
} catch (AwsException $exception) {
throw new ProviderException($this->createErrorMessage($exception));
}
}

Expand All @@ -66,9 +62,8 @@ public function pullVolumes(): bool {
public function pushVolumes(): bool {
try {
return $this->push("zip");
} catch (AwsException $e) {
Craft::$app->getErrorHandler()->logException($e);
throw new ProviderException("AWS Error (Code: '" . $e->getAWSErrorCode() . "')");
} catch (AwsException $exception) {
throw new ProviderException($this->createErrorMessage($exception));
}
}

Expand Down Expand Up @@ -172,4 +167,25 @@ private function getS3Client() {
'region' => $s3RegionName
]);
}

private function createErrorMessage($exception) {
Craft::$app->getErrorHandler()->logException($exception);
$awsMessage = $exception->getAwsErrorMessage();
$message = "AWS Error";
if ($awsMessage) {
if (strpos($awsMessage, "The request signature we calculated does not match the signature you provided") !== false) {
$message = $message . ' (Check secret key)';
} else {
$message = $message . ' ("' . $awsMessage . '")';
}
} else {
$awsMessage = $exception->getMessage();
if (strpos($awsMessage, 'Are you sure you are using the correct region for this bucket') !== false) {
$message = $message . " (Check region credentials)";
} else {
$message = $message . " (Check credentials)";
}
}
return $message;
}
}

0 comments on commit 2fbb0bb

Please sign in to comment.