Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- Enh #150: Cleanup templates, remove legacy code (@vjik)
- New #151: Add `$traceLink` parameter to `HtmlRenderer` to allow linking to trace files (@vjik)
- New #153: Add `UserExceptionInterface` to mark user exceptions (@vjik)

## 4.1.0 April 18, 2025

Expand Down
5 changes: 2 additions & 3 deletions src/Exception/UserException.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
use Exception;

/**
* UserException is the base class for exceptions that are meant to be shown to end users.
* Such exceptions are often caused by mistakes of end users.
* `UserException` represents an exception that is meant to be shown to end users.
*
* @final
*/
class UserException extends Exception
class UserException extends Exception implements UserExceptionInterface
{
}
15 changes: 15 additions & 0 deletions src/Exception/UserExceptionInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace Yiisoft\ErrorHandler\Exception;

use Throwable;

/**
* Interface for exceptions that are meant to be shown to end users.
* Such exceptions are often caused by mistakes of end users.
*/
interface UserExceptionInterface extends Throwable
{
}
4 changes: 2 additions & 2 deletions templates/production.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

use Yiisoft\ErrorHandler\Exception\UserException;
use Yiisoft\ErrorHandler\Exception\UserExceptionInterface;
use Yiisoft\ErrorHandler\Renderer\HtmlRenderer;
use Yiisoft\ErrorHandler\ThrowableRendererInterface;

Expand All @@ -9,7 +9,7 @@
* @var HtmlRenderer $this
*/

if ($throwable instanceof UserException) {
if ($throwable instanceof UserExceptionInterface) {
$name = $this->getThrowableName($throwable);
$message = $throwable->getMessage();
} else {
Expand Down
8 changes: 2 additions & 6 deletions tests/Factory/ThrowableResponseFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,8 @@ public function testHandleWithHeadRequestMethod(): void
$this->createThrowable(),
$this->createServerRequest('HEAD', ['Accept' => ['test/html']])
);
$response
->getBody()
->rewind();
$content = $response
->getBody()
->getContents();
$response->getBody()->rewind();
$content = $response->getBody()->getContents();

$this->assertEmpty($content);
$this->assertSame([HeaderRenderer::DEFAULT_ERROR_MESSAGE], $response->getHeader('X-Error-Message'));
Expand Down
Loading