Skip to content

Commit

Permalink
[10.x] Fix inconsistentcy between report and render methods (#47201)
Browse files Browse the repository at this point in the history
* Move mapException to top

* Add missing test to mapException
  • Loading branch information
xalaida authored May 24, 2023
1 parent 9475aac commit c95df92
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Illuminate/Foundation/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,8 @@ protected function context()
*/
public function render($request, Throwable $e)
{
$e = $this->prepareException($this->mapException($e));

if (method_exists($e, 'render') && $response = $e->render($request)) {
return Router::toResponse($request, $response);
}
Expand All @@ -381,8 +383,6 @@ public function render($request, Throwable $e)
return $e->toResponse($request);
}

$e = $this->prepareException($this->mapException($e));

if ($response = $this->renderViaCallbacks($request, $e)) {
return $response;
}
Expand Down
11 changes: 11 additions & 0 deletions tests/Foundation/FoundationExceptionsHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,17 @@ public function testReturnsCustomResponseWhenExceptionImplementsResponsable()
$this->assertSame('{"response":"My responsable exception response"}', $response);
}

public function testReturnsCustomResponseFromMappedException()
{
$this->handler->map(function (RuntimeException $e) {
return new ResponsableException();
});

$response = $this->handler->render($this->request, new RuntimeException)->getContent();

$this->assertSame('{"response":"My responsable exception response"}', $response);
}

public function testReturnsJsonWithoutStackTraceWhenAjaxRequestAndDebugFalseAndExceptionMessageIsMasked()
{
$this->config->shouldReceive('get')->with('app.debug', null)->once()->andReturn(false);
Expand Down

0 comments on commit c95df92

Please sign in to comment.