/** * 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'); }