diff --git a/packages/framework/src/Framework/Exceptions/FileNotFoundException.php b/packages/framework/src/Framework/Exceptions/FileNotFoundException.php index 8bd6298c279..417a18e3ea7 100644 --- a/packages/framework/src/Framework/Exceptions/FileNotFoundException.php +++ b/packages/framework/src/Framework/Exceptions/FileNotFoundException.php @@ -17,8 +17,8 @@ class FileNotFoundException extends Exception /** @var int */ protected $code = 404; - public function __construct(?string $path = null) + public function __construct(?string $path = null, ?string $customMessage = null) { - parent::__construct($path ? sprintf('File [%s] not found.', Hyde::pathToRelative($path)) : $this->message); + parent::__construct($customMessage ?? ($path ? sprintf('File [%s] not found.', Hyde::pathToRelative($path)) : $this->message)); } } diff --git a/packages/framework/tests/Unit/CustomExceptionsTest.php b/packages/framework/tests/Unit/CustomExceptionsTest.php index 30c7eec44cf..5103307be25 100644 --- a/packages/framework/tests/Unit/CustomExceptionsTest.php +++ b/packages/framework/tests/Unit/CustomExceptionsTest.php @@ -56,6 +56,11 @@ public function testFileNotFoundExceptionWithAbsolutePath() $this->assertSame('File [foo] not found.', (new FileNotFoundException(Hyde::path('foo')))->getMessage()); } + public function testFileNotFoundExceptionWithCustomPath() + { + $this->assertSame('foo', (new FileNotFoundException(customMessage: 'foo'))->getMessage()); + } + public function testRouteNotFoundExceptionWithDefaultMessage() { $this->assertSame('Route not found.', (new RouteNotFoundException())->getMessage());