bluejoyq

edit try catch in client for server timeout error

......@@ -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;
......
{
"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": 14692
"ngrokPid": 9812
}
......
......@@ -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
......
......@@ -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,10],
pastScore: [0,0,0,0,0,0],
};
export default ToggleLoading = (state = initialState, action) => {
......