/** * Handle if a exception was thrown during execution of show or initialization of the class. * * @internal * * @param \Exception $exception * @return AbstractView|void */ public static function handleException(\Exception $exception) { if ($exception instanceof \FeM\sPof\exception\InvalidParameterException) { foreach ($exception->getParameters() as $parameter) { Session::addErrorMsg($parameter['name'] . ' - ' . $parameter['description']); } } Logger::getInstance()->exception($exception); return null; }
/** * Mask actual exception for security reasons in case when it should not be exposed to API clients. * * Convert any exception into \Magento\Webapi\Exception. * * @param \Exception $exception Exception to convert to a WebAPI exception * * @return WebapiException */ public function maskException(\Exception $exception) { $isDevMode = $this->_appState->getMode() === State::MODE_DEVELOPER; $stackTrace = $isDevMode ? $exception->getTraceAsString() : null; if ($exception instanceof LocalizedException) { // Map HTTP codes for LocalizedExceptions according to exception type if ($exception instanceof NoSuchEntityException) { $httpCode = WebapiException::HTTP_NOT_FOUND; } elseif ($exception instanceof AuthorizationException || $exception instanceof AuthenticationException) { $httpCode = WebapiException::HTTP_UNAUTHORIZED; } else { // Input, Expired, InvalidState exceptions will fall to here $httpCode = WebapiException::HTTP_BAD_REQUEST; } if ($exception instanceof AbstractAggregateException) { $errors = $exception->getErrors(); } else { $errors = null; } $maskedException = new WebapiException($exception->getRawMessage(), $exception->getCode(), $httpCode, $exception->getParameters(), get_class($exception), $errors, $stackTrace); } elseif ($exception instanceof WebapiException) { $maskedException = $exception; } else { $message = $exception->getMessage(); $code = $exception->getCode(); //if not in Dev mode, make sure the message and code is masked for unanticipated exceptions if (!$isDevMode) { /** Log information about actual exception */ $reportId = $this->_critical($exception); $message = sprintf(self::INTERNAL_SERVER_ERROR_MSG, $reportId); $code = 0; } $maskedException = new WebapiException($message, $code, WebapiException::HTTP_INTERNAL_ERROR, [], '', null, $stackTrace); } return $maskedException; }