Skip to content

Commit de9d188

Browse files
committed
Expressive: Fixes throw Error|Exception when display_errors enabled
1 parent fb1255d commit de9d188

3 files changed

Lines changed: 16 additions & 0 deletions

File tree

spec/Integration/IntegrationViaErrorPreviewActionMiddlewareShownErrorSpec.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
$this->app->run($serverRequest);
8484
} catch (\Throwable $t) {
8585
expect($t)->toBeAnInstanceOf(\Throwable::class);
86+
expect($t->getMessage())->toContain('sample error preview');
8687
}
8788

8889
});

src/Middleware/Expressive.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ public function __construct(
3535
$this->renderer = $renderer;
3636
}
3737

38+
/**
39+
* @param ServerRequestInterface $request
40+
* @param ResponseInterface $response
41+
* @param callable $next
42+
*
43+
* @return ResponseInterface|void
44+
*/
3845
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next)
3946
{
4047
if (! $this->errorHeroModuleConfig['enable']) {
@@ -69,6 +76,8 @@ public function phpError()
6976

7077
/**
7178
* @param Error|Exception $e
79+
* @throws Error when 'display_errors' config is 1 and Error has thrown
80+
* @throws Exception when 'display_errors' config is 1 and Exception has thrown
7281
*
7382
* @return void
7483
*/
@@ -78,6 +87,10 @@ public function exceptionError($e, $request)
7887
$e
7988
);
8089

90+
if ($this->errorHeroModuleConfig['display-settings']['display_errors']) {
91+
throw $e;
92+
}
93+
8194
$this->showDefaultViewWhenDisplayErrorSetttingIsDisabled();
8295
}
8396

src/Middleware/Routed/Preview/ErrorPreviewAction.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,7 @@ public function __invoke(ServerRequestInterface $request, ResponseInterface $res
2121

2222
$array = [];
2323
$array[1]; // E_NOTICE
24+
25+
return $response;
2426
}
2527
}

0 commit comments

Comments
 (0)