/**
  * Returns a Status object representing the given exception using a localized message.
  *
  * @note: The returned Status will always be fatal, that is, $status->isOk() will return false.
  *
  * @see getExceptionMessage().
  *
  * @param Exception $error
  *
  * @return Status
  */
 protected function getExceptionStatus(Exception $error)
 {
     $msg = $this->exceptionLocalizer->getExceptionMessage($error);
     $status = Status::newFatal($msg);
     $status->setResult(false, $error->getMessage());
     return $status;
 }
Пример #2
0
 protected function showExceptionMessage(Exception $ex)
 {
     $msg = $this->exceptionLocalizer->getExceptionMessage($ex);
     $this->showErrorHTML($msg->parse(), 'error');
     // Report chained exceptions recursively
     if ($ex->getPrevious()) {
         $this->showExceptionMessage($ex->getPrevious());
     }
 }
 /**
  * Aborts the request with an error based on the given Exception.
  * This is intended as an alternative for ApiBase::dieUsage().
  *
  * If possible, a localized error message based on the exception is
  * included in the error sent to the client. Localization of errors
  * is attempted using the ExceptionLocalizer service provided to the
  * constructor. If that fails, dieUsage() is called, which in turn
  * attempts localization based on the error code.
  *
  * @see ApiBase::dieUsage()
  *
  * @param Exception $ex The exception to report. $ex->getMessage() will be used as the error's
  * free form description.
  * @param string $errorCode A code identifying the error.
  * @param int $httpRespCode The HTTP error code to send to the client
  * @param array|null $extradata Any extra data to include in the error report
  *
  * @throws LogicException
  */
 public function dieException(Exception $ex, $errorCode, $httpRespCode = 0, $extradata = array())
 {
     if ($this->localizer->hasExceptionMessage($ex)) {
         $message = $this->localizer->getExceptionMessage($ex);
         $key = $message->getKey();
         // NOTE: Ignore generic error messages, rely on the code instead!
         // XXX: No better way to do this?
         if ($key !== 'wikibase-error-unexpected') {
             $this->dieMessageObject($message, $errorCode, $httpRespCode, $extradata);
         }
     }
     $this->dieError($ex->getMessage(), $errorCode, $httpRespCode, $extradata);
     throw new LogicException('UsageException not thrown');
 }