Skip to content

Fix Web API error masking in production mode #2371

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

Merged
merged 1 commit into from
Mar 1, 2016
Merged
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
10 changes: 3 additions & 7 deletions lib/internal/Magento/Framework/Webapi/ErrorProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,10 @@ public function renderException(\Exception $exception, $httpCode = self::DEFAULT
*/
protected function _critical(\Exception $exception)
{
$exceptionClass = get_class($exception);
$reportId = uniqid("webapi-");
$exceptionForLog = new $exceptionClass(
/** Trace is added separately by critical. */
"Report ID: {$reportId}; Message: {$exception->getMessage()}",
$exception->getCode()
);
$this->_logger->critical($exceptionForLog);

$this->_logger->critical(new WebapiException\WebapiExceptionReport($reportId, $exception));

return $reportId;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace Magento\Framework\Webapi\Exception;

class WebapiExceptionReport extends \Exception
{
/**
* @var string
*/
private $reportId;

/**
* @param string $reportId
* @param \Exception $exception
*/
public function __construct($reportId, \Exception $exception)
{
$this->reportId = $reportId;

parent::__construct(
"Report ID: {$reportId}; Message: {$exception->getMessage()}",
$exception->getCode(),
$exception
);
}

/**
* @return string
*/
public function getReportId()
{
return $this->reportId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,22 @@ public function testMaskException($exception, $expectedHttpCode, $expectedMessag
);
}

/**
* Test logged exception is the same as the thrown one in production mode
*/
public function testCriticalExceptionStackTrace()
{
$thrownException = new \Exception('', 0);

$this->_loggerMock->expects($this->once())
->method('critical')
->will($this->returnCallback(function(\Exception $loggedException) use($thrownException) {
$this->assertSame($thrownException, $loggedException->getPrevious());
}));

$this->_errorProcessor->maskException($thrownException);
}

/**
* @return array
*/
Expand Down