[Задача 12794] Улучшил отображение ошибок на клиенте

parent 53dd5e30
...@@ -124,7 +124,12 @@ class Typos extends CI_Controller { ...@@ -124,7 +124,12 @@ class Typos extends CI_Controller {
$data["status"] = true; $data["status"] = true;
} }
$this->typo->editMessage($data); try {
$this->typo->editMessage($data);
} catch (Exception $e) {
$response["error"] = true;
$response["message"] = $e->getMessage();
}
return $this->output return $this->output
->set_content_type('application/json') ->set_content_type('application/json')
......
...@@ -249,6 +249,7 @@ class Typo extends CI_Model { ...@@ -249,6 +249,7 @@ class Typo extends CI_Model {
/** /**
* *
* @param $data * @param $data
* @throws Exception Если не удалось изменить статус сообщения
*/ */
function editMessage($data) { function editMessage($data) {
if (!$this->getMessageRights($data)) { if (!$this->getMessageRights($data)) {
...@@ -311,9 +312,9 @@ class Typo extends CI_Model { ...@@ -311,9 +312,9 @@ class Typo extends CI_Model {
* Отправляет запрос на исправление ошибки на сервер * Отправляет запрос на исправление ошибки на сервер
* *
* @param $data array Информация об опечатке * @param $data array Информация об опечатке
* @throws Exception Если произошла ошибка
*/ */
function correctTypo($data) { function correctTypo($data) {
/* TODO: брать из конфига */
$correctPath = $this->config->item("correction_path"); $correctPath = $this->config->item("correction_path");
$authToken = $this->config->item("typos_password"); $authToken = $this->config->item("typos_password");
$username = $this->config->item("typos_user"); $username = $this->config->item("typos_user");
...@@ -352,9 +353,13 @@ class Typo extends CI_Model { ...@@ -352,9 +353,13 @@ class Typo extends CI_Model {
log_message("debug", "corrected = {$data["corrected"]}"); log_message("debug", "corrected = {$data["corrected"]}");
if ( !($res = curl_exec($curl)) && curl_errno($curl) != 0 ) { if ( !($res = curl_exec($curl)) && curl_errno($curl) != 0 ) {
log_message("debug", "CorrectTypo errorCode: " . curl_errno($curl)); $errorCode = curl_errno($curl);
log_message("debug", "CorrectTypo errorText: " . curl_error($curl)); $errorText = curl_error($curl);
return;
log_message("debug", "CorrectTypo errorCode: " . $errorCode);
log_message("debug", "CorrectTypo errorText: " . $errorText);
throw $this->getExceptionForCurlError($errorCode, $url);
} }
log_message("debug", "response taken"); log_message("debug", "response taken");
...@@ -362,6 +367,23 @@ class Typo extends CI_Model { ...@@ -362,6 +367,23 @@ class Typo extends CI_Model {
curl_close($curl); curl_close($curl);
} }
/**
* Создает исключение, которое описывает ошибку запроса curl
*
* @param $errorCode integer Код ошибки curl
* @param $url string URL сервера
*
* @return Exception исключение
*/
private function getExceptionForCurlError($errorCode, $url)
{
if ($errorCode == CURLE_COULDNT_RESOLVE_HOST) {
return new Exception("\"$url\" не отвечает, попробуйте позже", 503);
} else {
return new Exception("Произошла ошибка при попытке исправить опечатку, попробуйте позже", 500);
}
}
} }
/**/ /**/
\ No newline at end of file
...@@ -26,12 +26,18 @@ export default class TypoList extends Component { ...@@ -26,12 +26,18 @@ export default class TypoList extends Component {
*/ */
acceptCorrection(typoId, corrected) { acceptCorrection(typoId, corrected) {
this._setTypoStatus(1, typoId, this.state.siteId, corrected) this._setTypoStatus(1, typoId, this.state.siteId, corrected)
.done(() => { .done((response) => {
alertify.success(`<p>Опечатка ${typoId} была подтверждена.</p> if (response.error === false) {
<p>Исправления применены к тексту, содержащему опечатку.</p>`); alertify.success(`<p>Опечатка ${typoId} была подтверждена.</p>
this.state.currentTypo++; <p>Исправления применены к тексту, содержащему опечатку.</p>`);
this._decrementSiteTyposCount();
this.forceUpdate(); this.state.currentTypo++;
this._decrementSiteTyposCount();
this.forceUpdate();
return;
}
alertify.error(response.message);
}) })
.fail(() => { .fail(() => {
alertify.error("Ошибка исправления опечатки, попробуйте позже"); alertify.error("Ошибка исправления опечатки, попробуйте позже");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment