Toggle navigation
Toggle navigation
This project
Loading...
Sign in
김서영
/
searchGuide
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
bluejoyq
2019-12-07 15:02:51 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
3431812d44c593d53d34294b6acc127bf2f80c5a
3431812d
1 parent
2f013120
edit try catch in client for server timeout error
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
42 additions
and
25 deletions
api/cliConnection.js
searchGuide/.expo/packager-info.json
searchGuide/lib/api.js
searchGuide/reducers/search.js
api/cliConnection.js
View file @
3431812
...
...
@@ -3,15 +3,6 @@ const search=require('./search');
const
machineRead
=
require
(
'./machineRead'
);
let
timer
=
(
)
=>
{
try
{
throw
new
Error
(
"TIMEOUT ERROR"
);
}
catch
(
err
)
{
res
.
json
(
{
"return_code"
:
-
1
,
"error_code"
:
err
.
message
}
);
res
.
status
(
504
);
//Gateway Timeout
return
false
;
}
}
/**
* @param req - request
...
...
@@ -23,7 +14,15 @@ const cliConnection = async ( req, res ) => {
analyzeData
=
{},
searchData
=
[];
setTimeout
(
timer
,
10000
);
let
timer
=
setTimeout
(
()
=>
{
try
{
throw
new
Error
(
"TIMEOUT ERROR"
);
}
catch
(
err
)
{
res
.
json
(
{
"return_code"
:
-
1
,
"error_code"
:
err
.
message
}
);
res
.
status
(
504
);
//Gateway Timeout
return
false
;
}
},
10000
);
try
{
clientData
=
req
.
body
.
data
;
...
...
searchGuide/.expo/packager-info.json
View file @
3431812
{
"devToolsPort"
:
19002
,
"expoServerPort"
:
19000
,
"packagerPort"
:
null
,
"packagerPid"
:
null
,
"packagerPort"
:
19001
,
"packagerPid"
:
30416
,
"expoServerNgrokUrl"
:
"https://ru-c66.bluejoy.searchguide.exp.direct"
,
"packagerNgrokUrl"
:
"https://packager.ru-c66.bluejoy.searchguide.exp.direct"
,
"ngrokPid"
:
1469
2
"ngrokPid"
:
981
2
}
...
...
searchGuide/lib/api.js
View file @
3431812
...
...
@@ -5,8 +5,9 @@ import { SERVER_URL } from 'react-native-dotenv';
export
const
sendSearch
=
async
(
searchText
)
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
if
(
searchText
===
""
||
searchText
.
length
>
30
){
resolve
({
"return_code"
:
-
1
,
"error_code"
:
"검색 단어를 확인해 주세요!"
});
}
else
{
resolve
({
"return_code"
:
-
1
,
"error_code"
:
"검색 단어를 입력해주세요."
});
}
else
{
axios
(
{
headers
:
{
...
...
@@ -24,14 +25,12 @@ export const sendSearch = async (searchText) => {
)
.
then
((
response
)
=>
{
resolve
(
filter
(
response
.
data
))
clearTimeout
(
timer
);
})
.
catch
(
error
=>
{
clearTimeout
(
timer
);
throw
new
Error
(
error
);
});
}
let
timer
=
setTimeout
(
()
=>
{
throw
new
Error
(
"time out"
);}
,
10000
)
})
}
\ No newline at end of file
...
...
searchGuide/reducers/search.js
View file @
3431812
...
...
@@ -9,6 +9,7 @@ const SUCCESS = 'search/SUCCESS';
const
FAILURE
=
'search/FAILURE'
;
const
START
=
'search/START'
;
export
const
change
=
(
text
)
=>
({
type
:
CHANGE
,
text
,
...
...
@@ -22,24 +23,42 @@ export const load = () => async (dispatch) =>{
export
const
submit
=
(
text
)
=>
async
(
dispatch
)
=>
{
dispatch
(
{
type
:
START
});
const
timer
=
setTimeout
(
()
=>
{
Alert
.
alert
(
'오류가 발생했습니다.'
,
'서버 연결 에러 (시간 초과)'
,
[
{
text
:
'확인'
,
onPress
:
()
=>
{}},
],
);
dispatch
({
type
:
FAILURE
})
},
10000
);
try
{
//const response = await readTest()
const
response
=
await
sendSearch
(
text
.
nativeEvent
.
text
);
// 에러시 error throw
if
(
response
.
return_code
==
-
1
){
throw
new
Error
(
response
.
error_code
)};
let
tempScore
=
scoring
(
response
.
return_data
);
await
sqlite
.
insert
(
tempScore
.
full
);
let
past
=
await
sqlite
.
select
();
past
=
past
.
map
(
elem
=>
elem
.
score
);
//dispatch( { type:SUCCESS, result:response }
dispatch
(
{
type
:
SUCCESS
,
result
:
response
,
past
:
past
,
score
:
tempScore
})
clearTimeout
(
timer
);
}
catch
(
err
){
console
.
log
(
err
);
/* Alert.alert(
'error'
,
Alert
.
alert
(
'오류가 발생했습니다.'
,
err
.
message
,
[
{
text
:
'확인'
,
onPress
:
()
=>
{}},
],
)
*/
)
;
dispatch
({
type
:
FAILURE
})
}
}
...
...
@@ -54,7 +73,7 @@ const initialState = {
},
score
:
{},
isLoading
:
false
,
pastScore
:
[
10
,
10
,
10
,
10
,
10
,
1
0
],
pastScore
:
[
0
,
0
,
0
,
0
,
0
,
0
],
};
export
default
ToggleLoading
=
(
state
=
initialState
,
action
)
=>
{
...
...
Please
register
or
login
to post a comment