add request fail exception
This commit is contained in:
parent
175522f96c
commit
59a234ab71
44
cgvAjax.js
44
cgvAjax.js
|
|
@ -149,7 +149,7 @@ class cgvGetter {
|
|||
const generalSeatCnt = 2;
|
||||
// const startTime = moment('2024-02-05');
|
||||
// const endTIme = moment('2024-02-12');
|
||||
const tmRange = { start: '1100', end: '1800' };
|
||||
const tmRange = { start: '1200', end: '1800' };
|
||||
let targetYMD = null;
|
||||
let targetSchedule = null;
|
||||
|
||||
|
|
@ -161,10 +161,22 @@ class cgvGetter {
|
|||
//==================================================
|
||||
while (1) {
|
||||
// 스케줄 데이터 요청
|
||||
const { cookies, data: result } = await this.getResultData(mgCD, targetYMD); // 20035290 듄, 20035256 웡카
|
||||
let cookies, result;
|
||||
let attempts = 0;
|
||||
while (attempts < 10) {
|
||||
const response = await this.getResultData(mgCD, targetYMD);
|
||||
if (response) {
|
||||
({ cookies, data: result } = response);
|
||||
break;
|
||||
}
|
||||
attempts++;
|
||||
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||
}
|
||||
if (!cookies && !result) {
|
||||
await __ERROR__(`사유: 스케줄 추출 작업 에러 / 현재시간: ${moment().format('YYYY-MM-DD HH:mm:ss')}`);
|
||||
return -1
|
||||
}
|
||||
|
||||
// 예외 - 요청 성공 확인
|
||||
if (result === null) throw new Error(`\t> Request failed`);
|
||||
// 예외(실험적) - 응답 데이터 구조 확인
|
||||
if (!result.hasOwnProperty('d')) throw new Error(`\t> Response lacks the expected "d" property`);
|
||||
const gScheduleList = JSON.parse(result.d);
|
||||
|
|
@ -188,10 +200,10 @@ class cgvGetter {
|
|||
targetYMD = util.YMDConvert(targetDates[0]);
|
||||
await __INFO__(`조건 부합 날짜 식별됨 - 시도: ${++attemptCnt} / 시간: ${moment().format('MM-DD HH:mm:ss')} / 경과: ${init.fromNow()}`);
|
||||
continue
|
||||
|
||||
//==================================================
|
||||
// requset - 시간표 찾았을 때
|
||||
//==================================================
|
||||
|
||||
//==================================================
|
||||
// requset - 시간표 찾았을 때
|
||||
//==================================================
|
||||
} else if (targetYMD !== null && targetSchedule === null) {
|
||||
/* ++++++++++++ 남은 좌석 수 필터링 추가 'SeatRemainCnt' */
|
||||
// 상영시간표 추출
|
||||
|
|
@ -288,7 +300,21 @@ class cgvGetter {
|
|||
Origin: 'https://m.cgv.co.kr',
|
||||
Cookie: COOKIE
|
||||
}
|
||||
const { cookies: loginCookies } = await this._post(this.loginAspx, loginParam, loginHeaders);
|
||||
let loginCookies;
|
||||
let attempts = 0;
|
||||
while (attempts < 10) {
|
||||
const response = await this._post(this.loginAspx, loginParam, loginHeaders);
|
||||
if (response) {
|
||||
({ cookies: loginCookies } = response);
|
||||
break;
|
||||
}
|
||||
attempts++;
|
||||
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||
}
|
||||
if (!loginCookies) {
|
||||
await __ERROR__(`사유: 쿠키 추출 작업 에러 / 현재시간: ${moment().format('YYYY-MM-DD HH:mm:ss')}`);
|
||||
return -1
|
||||
}
|
||||
/* ++++++++++++ 예외 추가 or 예외 자체를 요청과정에 합병 */
|
||||
|
||||
// cookie list -> cookie string
|
||||
|
|
|
|||
Loading…
Reference in New Issue