Skip to content
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

Fix issue #4501 Exception noise from OAuth and REST (API2 ) #4642

Open
wants to merge 2 commits into
base: main
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
20 changes: 19 additions & 1 deletion app/code/core/Mage/Api2/Exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,36 @@
*/
class Mage_Api2_Exception extends Exception
{
/**
* Log the exception in the log file?
* @var bool
*/
protected $_shouldLog = true;

/**
* Exception constructor
*
* @param string $message
* @param int $code
* @param bool $shouldLog
*/
public function __construct($message, $code)
public function __construct($message, $code, $shouldLog = true)
{
if ($code <= 100 || $code >= 599) {
throw new Exception(sprintf('Invalid Exception code "%d"', $code));
}

$this->_shouldLog = $shouldLog;
parent::__construct($message, $code);
}

/**
* Check if exception should be logged
*
* @return bool
*/
public function shouldLog()
{
return $this->_shouldLog;
}
}
8 changes: 6 additions & 2 deletions app/code/core/Mage/Api2/Model/Resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -613,9 +613,10 @@ protected function _render($data)
*
* @param string $message
* @param int $code
* @param bool $shouldLog Log the error in the log file?
* @throws Mage_Api2_Exception
*/
protected function _critical($message, $code = null)
protected function _critical($message, $code = null, $shouldLog = true)
{
if ($code === null) {
$errors = $this->_getCriticalErrors();
Expand All @@ -627,7 +628,10 @@ protected function _critical($message, $code = null)
}
$code = $errors[$message];
}
throw new Mage_Api2_Exception($message, $code);

Mage::dispatchEvent('api2_resource_critical', ['resource' => $this, 'message' => $message, 'code' => $code]);

throw new Mage_Api2_Exception($message, $code, $shouldLog);
}

/**
Expand Down
5 changes: 5 additions & 0 deletions app/code/core/Mage/Api2/Model/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ public function run()
if ($response->isException()) {
throw new Mage_Api2_Exception('Unhandled simple errors.', self::HTTP_INTERNAL_ERROR);
}
} catch (Mage_Api2_Exception $e) {
if ($e->shouldLog()) {
Mage::logException($e);
}
$this->_renderException($e, $renderer, $response);
} catch (Exception $e) {
Mage::logException($e);
$this->_renderException($e, $renderer, $response);
Expand Down
Loading