vito/app/SourceControlProviders/AbstractSourceControlProvider.php
Saeed Vaziry 428140b931
refactoring (#116)
- refactoring architecture
- fix incomplete ssh logs
- code editor for scripts in the app
- remove Jobs and SSHCommands
2024-03-14 20:03:43 +01:00

40 lines
1.0 KiB
PHP
Executable File

<?php
namespace App\SourceControlProviders;
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);
}
}
}