diff --git a/src/Features/UniversalRoutes.php b/src/Features/UniversalRoutes.php index 685bd17e..9c9ec5fb 100644 --- a/src/Features/UniversalRoutes.php +++ b/src/Features/UniversalRoutes.php @@ -30,7 +30,11 @@ class UniversalRoutes implements Feature return $next($request); } - return $originalOnFail($exception, $request, $next); + if ($originalOnFail) { + return $originalOnFail($exception, $request, $next); + } + + throw $exception; }; } } diff --git a/tests/DomainTest.php b/tests/DomainTest.php index 9c1bac28..01342d78 100644 --- a/tests/DomainTest.php +++ b/tests/DomainTest.php @@ -10,6 +10,7 @@ use Stancl\Tenancy\Database\Models; use Stancl\Tenancy\Database\Models\Domain; use Stancl\Tenancy\Exceptions\DomainOccupiedByOtherTenantException; use Stancl\Tenancy\Exceptions\TenantCouldNotBeIdentifiedOnDomainException; +use Stancl\Tenancy\Features\UniversalRoutes; use Stancl\Tenancy\Middleware\InitializeTenancyByDomain; use Stancl\Tenancy\Resolvers\DomainTenantResolver; @@ -105,6 +106,17 @@ class DomainTest extends TestCase ->assertSee('foo'); } + /** @test */ + public function not_defining_onfail_customized_logic_throw_correct_exception_when_universal_route_feature_enabled() + { + // Enable UniversalRoute feature + Route::middlewareGroup('universal', []); + config(['tenancy.features' => [UniversalRoutes::class]]); + + $this->expectException(TenantCouldNotBeIdentifiedOnDomainException::class); + $this->withoutExceptionHandling()->get('http://foo.localhost/foo/abc/xyz'); + } + /** @test */ public function domains_are_always_lowercase() {