From 17fecf29a12b8aed6ce83499565ae2967b4ad089 Mon Sep 17 00:00:00 2001 From: Abrar Ahmad Date: Fri, 22 Jul 2022 18:35:37 +0500 Subject: [PATCH] throw correct exception when `$originalOnFail()` is null --- src/Features/UniversalRoutes.php | 6 +++++- tests/DomainTest.php | 12 ++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) 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() {