Skip to content

Commit

Permalink
Throw exception if error code >=400
Browse files Browse the repository at this point in the history
  • Loading branch information
vermakhushboo committed Oct 17, 2023
1 parent abe1414 commit c293d06
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
9 changes: 5 additions & 4 deletions src/VCS/Adapter/Git/GitHub.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,12 @@ public function deleteRepository(string $owner, string $repositoryName): bool

$response = $this->call(self::METHOD_DELETE, $url, ['Authorization' => "Bearer $this->accessToken"]);

if ($response['headers']['status-code'] == 204) {
return true;
} else {
throw new RepositoryNotFound("Repository not found");
$statusCode = $response['headers']['status-code'];

if ($statusCode >= 400) {
throw new Exception("Deleting repository $repositoryName failed with status code $statusCode");
}
return true;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/VCS/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace Utopia\Tests;

use Exception;
use PHPUnit\Framework\TestCase;
use Utopia\App;
use Utopia\VCS\Adapter\Git;
use Utopia\VCS\Exception\RepositoryNotFound;

abstract class Base extends TestCase
{
Expand Down Expand Up @@ -97,7 +97,7 @@ public function testDeleteRepository(): void
{
$result = $this->vcsAdapter->deleteRepository('test-kh', 'new-repo');
$this->assertEquals(true, $result);
$this->expectException(RepositoryNotFound::class);
$this->expectException(Exception::class);
$result = $this->vcsAdapter->deleteRepository('test-kh', 'new-repo-2');
}
}

0 comments on commit c293d06

Please sign in to comment.