Skip to content

Commit

Permalink
Merge pull request #1053 from spiral/remove-deprecate
Browse files Browse the repository at this point in the history
Revert ServerErrorException deprecation
  • Loading branch information
butschster committed Jan 4, 2024
2 parents 0ef6c11 + 80e13d0 commit 7bd6893
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
10 changes: 8 additions & 2 deletions src/Exceptions/src/ExceptionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
use Spiral\Exceptions\Renderer\PlainRenderer;
use Spiral\Filters\Exception\AuthorizationException;
use Spiral\Filters\Exception\ValidationException;
use Spiral\Http\Exception\ClientException;
use Spiral\Http\Exception\ClientException\BadRequestException;
use Spiral\Http\Exception\ClientException\ForbiddenException;
use Spiral\Http\Exception\ClientException\NotFoundException;
use Spiral\Http\Exception\ClientException\UnauthorizedException;

/**
* The class is responsible for:
Expand All @@ -29,7 +32,10 @@ class ExceptionHandler implements ExceptionHandlerInterface
protected array $reporters = [];
protected mixed $output = null;
protected array $nonReportableExceptions = [
ClientException::class,
BadRequestException::class,
ForbiddenException::class,
NotFoundException::class,
UnauthorizedException::class,
AuthorizationException::class,
ValidationException::class,
];
Expand Down
15 changes: 11 additions & 4 deletions src/Exceptions/tests/ExceptionHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use Spiral\Exceptions\ExceptionReporterInterface;
use Spiral\Filters\Exception\AuthorizationException;
use Spiral\Filters\Exception\ValidationException;
use Spiral\Http\Exception\ClientException;
use Spiral\Http\Exception\ClientException\BadRequestException;
use Spiral\Http\Exception\ClientException\ForbiddenException;
use Spiral\Http\Exception\ClientException\NotFoundException;
use Spiral\Http\Exception\ClientException\UnauthorizedException;
Expand Down Expand Up @@ -116,15 +116,21 @@ public function testAddNonReportableExceptions(): void
$handler = $this->makeEmptyErrorHandler();
$ref = new \ReflectionProperty($handler, 'nonReportableExceptions');
$this->assertSame([
ClientException::class,
BadRequestException::class,
ForbiddenException::class,
NotFoundException::class,
UnauthorizedException::class,
AuthorizationException::class,
ValidationException::class,
], $ref->getValue($handler));

$handler->dontReport(\DomainException::class);

$this->assertSame([
ClientException::class,
BadRequestException::class,
ForbiddenException::class,
NotFoundException::class,
UnauthorizedException::class,
AuthorizationException::class,
ValidationException::class,
\DomainException::class
Expand All @@ -147,7 +153,8 @@ private function makeErrorHandler(): ExceptionHandler

public static function nonReportableExceptionsDataProvider(): \Traversable
{
yield [new class extends ClientException {}];
yield [new BadRequestException()];
yield [new class extends BadRequestException {}];
yield [new NotFoundException()];
yield [new class extends NotFoundException {}];
yield [new ForbiddenException()];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

/**
* HTTP 500 exception.
* @deprecated since v3.12
*/
class ServerErrorException extends ClientException
{
Expand Down
7 changes: 7 additions & 0 deletions src/Http/tests/ExceptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ public function testUnauthorized(): void
$this->assertSame(401, $e->getCode());
}

public function testServerError(): void
{
$e = new ClientException\ServerErrorException();
$this->assertSame(500, $e->getCode());
}

#[DataProvider('allExceptionsWithPreviousSet')]
public function testPreviousSetter(\Throwable $exception): void
{
Expand All @@ -57,6 +63,7 @@ public static function allExceptionsWithPreviousSet(): \Generator
yield [new Exception\ClientException\ForbiddenException('', new \Exception())];
yield [new Exception\ClientException\NotFoundException('', new \Exception())];
yield [new Exception\ClientException\UnauthorizedException('', new \Exception())];
yield [new Exception\ClientException\ServerErrorException('', new \Exception())];
yield [new Exception\ClientException(0, '', new \Exception())];
yield [new Exception\DotNotFoundException('', 0, new \Exception())];
yield [new Exception\HttpException('', 0, new \Exception())];
Expand Down

0 comments on commit 7bd6893

Please sign in to comment.