mirror of
https://github.com/vitodeploy/vito.git
synced 2025-06-30 21:46:16 +00:00
init
This commit is contained in:
40
app/SourceControlProviders/AbstractSourceControlProvider.php
Executable file
40
app/SourceControlProviders/AbstractSourceControlProvider.php
Executable file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\SourceControlProviders;
|
||||
|
||||
use App\Contracts\SourceControlProvider;
|
||||
use App\Exceptions\RepositoryNotFound;
|
||||
use App\Exceptions\RepositoryPermissionDenied;
|
||||
use App\Exceptions\SourceControlIsNotConnected;
|
||||
use App\Models\SourceControl;
|
||||
use Illuminate\Http\Client\Response;
|
||||
|
||||
abstract class AbstractSourceControlProvider implements SourceControlProvider
|
||||
{
|
||||
protected SourceControl $sourceControl;
|
||||
|
||||
public function __construct(SourceControl $sourceControl)
|
||||
{
|
||||
$this->sourceControl = $sourceControl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws SourceControlIsNotConnected
|
||||
* @throws RepositoryNotFound
|
||||
* @throws RepositoryPermissionDenied
|
||||
*/
|
||||
protected function handleResponseErrors(Response $res, string $repo): void
|
||||
{
|
||||
if ($res->status() == 401) {
|
||||
throw new SourceControlIsNotConnected($this->sourceControl);
|
||||
}
|
||||
|
||||
if ($res->status() == 404) {
|
||||
throw new RepositoryNotFound($repo);
|
||||
}
|
||||
|
||||
if ($res->status() == 403) {
|
||||
throw new RepositoryPermissionDenied($repo);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user