Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
R
retypos-server
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
eterfund
retypos-server
Commits
9b5f7847
Commit
9b5f7847
authored
May 25, 2018
by
Георгий Попов
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Задача 12794] Улучшил отображение ошибок на клиенте
parent
53dd5e30
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
5 deletions
+39
-5
Typos.php
cp/application/controllers/users/Typos.php
+5
-0
Typo.php
cp/application/models/Typo.php
+27
-4
index.jsx
cp/javascript/src/components/TypoList/index.jsx
+7
-1
No files found.
cp/application/controllers/users/Typos.php
View file @
9b5f7847
...
...
@@ -124,7 +124,12 @@ class Typos extends CI_Controller {
$data
[
"status"
]
=
true
;
}
try
{
$this
->
typo
->
editMessage
(
$data
);
}
catch
(
Exception
$e
)
{
$response
[
"error"
]
=
true
;
$response
[
"message"
]
=
$e
->
getMessage
();
}
return
$this
->
output
->
set_content_type
(
'application/json'
)
...
...
cp/application/models/Typo.php
View file @
9b5f7847
...
...
@@ -249,6 +249,7 @@ class Typo extends CI_Model {
/**
*
* @param $data
* @throws Exception Если не удалось изменить статус сообщения
*/
function
editMessage
(
$data
)
{
if
(
!
$this
->
getMessageRights
(
$data
))
{
...
...
@@ -311,9 +312,9 @@ class Typo extends CI_Model {
* Отправляет запрос на исправление ошибки на сервер
*
* @param $data array Информация об опечатке
* @throws Exception Если произошла ошибка
*/
function
correctTypo
(
$data
)
{
/* TODO: брать из конфига */
$correctPath
=
$this
->
config
->
item
(
"correction_path"
);
$authToken
=
$this
->
config
->
item
(
"typos_password"
);
$username
=
$this
->
config
->
item
(
"typos_user"
);
...
...
@@ -352,9 +353,13 @@ class Typo extends CI_Model {
log_message
(
"debug"
,
"corrected =
{
$data
[
"corrected"
]
}
"
);
if
(
!
(
$res
=
curl_exec
(
$curl
))
&&
curl_errno
(
$curl
)
!=
0
)
{
log_message
(
"debug"
,
"CorrectTypo errorCode: "
.
curl_errno
(
$curl
));
log_message
(
"debug"
,
"CorrectTypo errorText: "
.
curl_error
(
$curl
));
return
;
$errorCode
=
curl_errno
(
$curl
);
$errorText
=
curl_error
(
$curl
);
log_message
(
"debug"
,
"CorrectTypo errorCode: "
.
$errorCode
);
log_message
(
"debug"
,
"CorrectTypo errorText: "
.
$errorText
);
throw
$this
->
getExceptionForCurlError
(
$errorCode
,
$url
);
}
log_message
(
"debug"
,
"response taken"
);
...
...
@@ -362,6 +367,23 @@ class Typo extends CI_Model {
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
cp/javascript/src/components/TypoList/index.jsx
View file @
9b5f7847
...
...
@@ -26,12 +26,18 @@ export default class TypoList extends Component {
*/
acceptCorrection
(
typoId
,
corrected
)
{
this
.
_setTypoStatus
(
1
,
typoId
,
this
.
state
.
siteId
,
corrected
)
.
done
(()
=>
{
.
done
((
response
)
=>
{
if
(
response
.
error
===
false
)
{
alertify
.
success
(
`<p>Опечатка
${
typoId
}
была подтверждена.</p>
<p>Исправления применены к тексту, содержащему опечатку.</p>`
);
this
.
state
.
currentTypo
++
;
this
.
_decrementSiteTyposCount
();
this
.
forceUpdate
();
return
;
}
alertify
.
error
(
response
.
message
);
})
.
fail
(()
=>
{
alertify
.
error
(
"Ошибка исправления опечатки, попробуйте позже"
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment