generated from spatie/package-skeleton-php
-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: always throw exceptions on error
- Loading branch information
1 parent
1951dfa
commit d0e0174
Showing
4 changed files
with
108 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace Vidwan\TenantBuckets\Exceptions; | ||
|
||
use Aws\Exception\AwsException; | ||
use Exception; | ||
use Throwable; | ||
|
||
abstract class BaseException extends Exception | ||
{ | ||
|
||
protected array $data; | ||
|
||
protected AwsException $awsException; | ||
|
||
public function __construct(string $message = "", int $code = 0, Throwable|null $previous = null) | ||
{ | ||
parent::__construct($message, $code, $previous); | ||
} | ||
|
||
public function getAwsException(): AwsException | ||
{ | ||
return $this->awsException; | ||
} | ||
|
||
public function getData(): array | ||
{ | ||
return $this->data; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace Vidwan\TenantBuckets\Exceptions; | ||
|
||
use Aws\Exception\AwsException; | ||
use Stancl\Tenancy\Contracts\Tenant; | ||
|
||
class CreateBucketException extends BaseException | ||
{ | ||
|
||
public function __construct( | ||
protected Tenant $tenant, | ||
protected string $bucketName, | ||
protected AwsException $awsException | ||
) | ||
{ | ||
$message = "[tenant-buckets] Error: (Tenant ID: {$tenant->id}) {$awsException->getAwsErrorMessage()}"; | ||
parent::__construct($message,$awsException->getCode(), $awsException); | ||
|
||
$this->setData(); | ||
} | ||
|
||
private function setData(): static | ||
{ | ||
$this->data = [ | ||
'tenant' => $this->tenant->id, | ||
'bucket' => $this->bucketName, | ||
'error_code' => $this->awsException->getAwsErrorCode(), | ||
'error_type' => $this->awsException->getAwsErrorType(), | ||
'error_message' => $this->awsException->getAwsErrorMessage(), | ||
'response' => $this->awsException->getResponse(), | ||
]; | ||
return $this; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace Vidwan\TenantBuckets\Exceptions; | ||
|
||
use Aws\Exception\AwsException; | ||
use Stancl\Tenancy\Contracts\Tenant; | ||
|
||
class DeleteBucketException extends BaseException | ||
{ | ||
|
||
public function __construct( | ||
protected Tenant $tenant, | ||
protected string $bucketName, | ||
protected AwsException $awsException | ||
) | ||
{ | ||
$message = "[tenant-buckets] Error: (Tenant ID: {$tenant->id}) {$awsException->getAwsErrorMessage()}"; | ||
parent::__construct($message,$awsException->getCode(), $awsException); | ||
|
||
$this->setData(); | ||
} | ||
|
||
private function setData(): static | ||
{ | ||
$this->data = [ | ||
'tenant' => $this->tenant->id, | ||
'bucket' => $this->bucketName, | ||
'error_code' => $this->awsException->getAwsErrorCode(), | ||
'error_type' => $this->awsException->getAwsErrorType(), | ||
'error_message' => $this->awsException->getAwsErrorMessage(), | ||
'response' => $this->awsException->getResponse(), | ||
]; | ||
return $this; | ||
} | ||
|
||
} |