Skip to content

Commit ee6f28d

Browse files
author
Oleksii Korshenko
committed
Merge remote-tracking branch 'skolodyazhnyy/fix-exception-masking' into minline-develop
2 parents f2efe76 + c60b3a7 commit ee6f28d

File tree

3 files changed

+53
-7
lines changed

3 files changed

+53
-7
lines changed

lib/internal/Magento/Framework/Webapi/ErrorProcessor.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -189,14 +189,10 @@ public function renderException(\Exception $exception, $httpCode = self::DEFAULT
189189
*/
190190
protected function _critical(\Exception $exception)
191191
{
192-
$exceptionClass = get_class($exception);
193192
$reportId = uniqid("webapi-");
194-
$exceptionForLog = new $exceptionClass(
195-
/** Trace is added separately by critical. */
196-
"Report ID: {$reportId}; Message: {$exception->getMessage()}",
197-
$exception->getCode()
198-
);
199-
$this->_logger->critical($exceptionForLog);
193+
194+
$this->_logger->critical(new WebapiException\WebapiExceptionReport($reportId, $exception));
195+
200196
return $reportId;
201197
}
202198

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace Magento\Framework\Webapi\Exception;
4+
5+
class WebapiExceptionReport extends \Exception
6+
{
7+
/**
8+
* @var string
9+
*/
10+
private $reportId;
11+
12+
/**
13+
* @param string $reportId
14+
* @param \Exception $exception
15+
*/
16+
public function __construct($reportId, \Exception $exception)
17+
{
18+
$this->reportId = $reportId;
19+
20+
parent::__construct(
21+
"Report ID: {$reportId}; Message: {$exception->getMessage()}",
22+
$exception->getCode(),
23+
$exception
24+
);
25+
}
26+
27+
/**
28+
* @return string
29+
*/
30+
public function getReportId()
31+
{
32+
return $this->reportId;
33+
}
34+
}

lib/internal/Magento/Framework/Webapi/Test/Unit/ErrorProcessorTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,22 @@ public function testMaskException($exception, $expectedHttpCode, $expectedMessag
225225
);
226226
}
227227

228+
/**
229+
* Test logged exception is the same as the thrown one in production mode
230+
*/
231+
public function testCriticalExceptionStackTrace()
232+
{
233+
$thrownException = new \Exception('', 0);
234+
235+
$this->_loggerMock->expects($this->once())
236+
->method('critical')
237+
->will($this->returnCallback(function(\Exception $loggedException) use($thrownException) {
238+
$this->assertSame($thrownException, $loggedException->getPrevious());
239+
}));
240+
241+
$this->_errorProcessor->maskException($thrownException);
242+
}
243+
228244
/**
229245
* @return array
230246
*/

0 commit comments

Comments
 (0)