Skip to content

Commit dc8e759

Browse files
authored
Merge pull request #1197 from hydephp/update-RouteNotFoundException-to-support-custom-message
Update RouteNotFoundException to support custom message
2 parents 5b0ffd1 + 9be9fad commit dc8e759

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

packages/framework/src/Framework/Exceptions/RouteNotFoundException.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,14 @@ class RouteNotFoundException extends Exception
1414
/** @var int */
1515
protected $code = 404;
1616

17-
public function __construct(?string $routeKey = null)
17+
public function __construct(?string $routeKey = null, ?string $message = null)
1818
{
1919
if ($routeKey) {
2020
$this->message = "Route not found: '$routeKey'";
2121
}
22+
if ($message) {
23+
$this->message = $message;
24+
}
2225

2326
parent::__construct($this->message, $this->code);
2427
}

packages/framework/tests/Unit/RouteNotFoundExceptionTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,13 @@ public function test_it_throws_an_exception_when_page_type_is_not_supported()
2727

2828
throw new RouteNotFoundException('not-found');
2929
}
30+
31+
public function test_it_throws_an_exception_with_custom_message()
32+
{
33+
$this->expectException(RouteNotFoundException::class);
34+
$this->expectExceptionMessage('Custom message');
35+
$this->expectExceptionCode(404);
36+
37+
throw new RouteNotFoundException(null, 'Custom message');
38+
}
3039
}

0 commit comments

Comments
 (0)