Skip to content

Improve exception handling #31598

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: 2.4-develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions lib/internal/Magento/Framework/App/ExceptionHandler.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2019 Adobe
* All Rights Reserved.
*/
declare(strict_types=1);

Expand Down Expand Up @@ -99,7 +99,7 @@ private function handleDeveloperMode(
}
$response->clearHeader('Location');
$response->setHttpResponseCode(500);
$response->setHeader('Content-Type', 'text/plain');
$response->setHeader('Content-Type', 'text/html');
$response->setBody($this->buildContentFromException($exception));
$response->sendResponse();
return true;
Expand All @@ -122,11 +122,11 @@ private function buildContentFromException(\Exception $exception): string
$exceptions[] = $exception;
} while ($exception = $exception->getPrevious());

$buffer = sprintf("%d exception(s):\n", count($exceptions));
$buffer = sprintf("<div>%d exception(s):</div>\n", count($exceptions));

foreach ($exceptions as $index => $exception) {
$buffer .= sprintf(
"Exception #%d (%s): %s\n",
"<div>Exception #%d (%s): %s</div>\n",
$index,
get_class($exception),
$exception->getMessage()
Expand All @@ -135,7 +135,7 @@ private function buildContentFromException(\Exception $exception): string

foreach ($exceptions as $index => $exception) {
$buffer .= sprintf(
"\nException #%d (%s): %s\n%s\n",
"<br/>\n<div>Exception #%d (%s): %s\n%s</div>\n",
$index,
get_class($exception),
$exception->getMessage(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2019 Adobe
* All Rights Reserved.
*/
declare(strict_types=1);

Expand Down Expand Up @@ -125,8 +125,8 @@ public function testHandleDeveloperMode()
->with(500);
$this->responseMock->expects($this->once())
->method('setHeader')
->with('Content-Type', 'text/plain');
$constraint = new StringStartsWith('1 exception(s):');
->with('Content-Type', 'text/html');
$constraint = new StringStartsWith('<div>1 exception(s):</div>');
$this->responseMock->expects($this->once())
->method('setBody')
->with($constraint);
Expand Down