88 \Psr\Log\LoggerInterface
$logger,
90 Json $serializer =
null 93 $this->_appState = $appState;
113 $stackTrace = $isDevMode ? $exception->getTraceAsString() :
null;
115 if ($exception instanceof WebapiException) {
116 $maskedException = $exception;
120 $httpCode = WebapiException::HTTP_NOT_FOUND;
124 $httpCode = WebapiException::HTTP_UNAUTHORIZED;
127 $httpCode = WebapiException::HTTP_BAD_REQUEST;
136 $maskedException =
new WebapiException(
138 $exception->getCode(),
141 get_class($exception),
146 $message = $exception->getMessage();
147 $code = $exception->getCode();
151 $reportId = $this->
_critical($exception);
152 $message = sprintf(self::INTERNAL_SERVER_ERROR_MSG, $reportId);
155 $maskedException =
new WebapiException(
158 WebapiException::HTTP_INTERNAL_ERROR,
165 return $maskedException;
181 $exception instanceof \Magento\Framework\Webapi\Exception
183 $this->
renderErrorMessage($exception->getMessage(), $exception->getTraceAsString(), $httpCode);
185 $reportId = $this->
_critical($exception);
187 new Phrase(
'Internal Error. Details are available in Magento log file. Report ID: %1', $reportId),
188 'Trace is not available.',
203 $reportId = uniqid(
"webapi-");
204 $message =
"Report ID: {$reportId}; Message: {$exception->getMessage()}";
205 $code = $exception->getCode();
207 $this->_logger->critical($exception);
221 $trace =
'Trace is not available.',
222 $httpCode = self::DEFAULT_ERROR_HTTP_CODE
224 if (isset($_SERVER[
'HTTP_ACCEPT']) && strstr($_SERVER[
'HTTP_ACCEPT'],
'xml')) {
226 $mimeType =
'application/xml';
230 $mimeType =
'application/json';
233 header(
'HTTP/1.1 ' . ($httpCode ? $httpCode : self::DEFAULT_ERROR_HTTP_CODE));
234 header(
'Content-Type: ' . $mimeType .
'; charset=' . self::DEFAULT_RESPONSE_CHARSET);
251 $message = [
'code' => $httpCode,
'message' => $errorMessage];
253 if ($isDeveloperMode) {
256 $errorData[
'messages'][
'error'][] =
$message;
259 $errorData = $this->encoder->encode($errorData);
262 $errorData =
'<?xml version="1.0"?>' 267 .
'<code>' . $httpCode .
'</code>' 268 .
'<message><![CDATA[' . $errorMessage .
']]></message>' 269 . ($isDeveloperMode ?
'<trace><![CDATA[' . $trace .
']]></trace>' :
'')
286 register_shutdown_function([$this, self::DEFAULT_SHUTDOWN_FUNCTION]);
297 $fatalErrorFlag = E_ERROR | E_USER_ERROR | E_PARSE | E_CORE_ERROR | E_COMPILE_ERROR | E_RECOVERABLE_ERROR;
298 $error = error_get_last();
299 if ($error && $error[
'type'] & $fatalErrorFlag) {
300 $errorMessage =
"Fatal Error: '{$error['message']}' in '{$error['file']}' on line {$error['line']}";
306 new Phrase(
'Server internal error. See details in report api/%1', [$reportId])
320 $this->directoryWrite->create(
'report/api');
321 $reportId = abs(intval(microtime(
true) * random_int(100, 1000)));
322 $this->directoryWrite->writeFile(
'report/api/' . $reportId, $this->serializer->serialize($reportData));
_saveFatalErrorReport($reportData)
elseif(isset( $params[ 'redirect_parent']))
renderException(\Exception $exception, $httpCode=self::DEFAULT_ERROR_HTTP_CODE)
const DEFAULT_RESPONSE_CHARSET
_formatError($errorMessage, $trace, $httpCode, $format)
const DEFAULT_ERROR_HTTP_CODE
registerShutdownFunction()
renderErrorMessage( $errorMessage, $trace='Trace is not available.', $httpCode=self::DEFAULT_ERROR_HTTP_CODE)
const DEFAULT_SHUTDOWN_FUNCTION
_critical(\Exception $exception)
__construct(\Magento\Framework\Json\Encoder $encoder, \Magento\Framework\App\State $appState, \Psr\Log\LoggerInterface $logger, \Magento\Framework\Filesystem $filesystem, Json $serializer=null)
maskException(\Exception $exception)
const INTERNAL_SERVER_ERROR_MSG