Skip to content

Commit

Permalink
Merge pull request #1398 from hydephp/custom-file-not-found-exception…
Browse files Browse the repository at this point in the history
…-messages

Add option for full control over the FileNotFoundException message
  • Loading branch information
caendesilva authored Oct 27, 2023
2 parents 6a413a8 + 2407396 commit 9f94f7f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ This serves two purposes:
### Added
- Added support for setting custom content when calling source file creator actions directly in https://github.com/hydephp/develop/pull/1393
- Added support for setting a custom post date when calling post file creator action directly in https://github.com/hydephp/develop/pull/1393
- Added optional `FileNotFoundException` constructor parameter to set a custom exception message https://github.com/hydephp/develop/pull/1398
- The realtime compiler dashboard is now interactive, and allows you to make edits to your project right from the browser https://github.com/hydephp/develop/pull/1392

### Changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
5 changes: 5 additions & 0 deletions packages/framework/tests/Unit/CustomExceptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit 9f94f7f

Please sign in to comment.