김서영

search.js add error check

...@@ -63,8 +63,12 @@ const searchToResult = (searchResult, result, keywordCheck) => { ...@@ -63,8 +63,12 @@ const searchToResult = (searchResult, result, keywordCheck) => {
63 result.push( searchResult ); 63 result.push( searchResult );
64 } 64 }
65 } else if( keywordCheck ) { 65 } else if( keywordCheck ) {
66 - 66 + // 공백 제거하고 비교
67 -}} 67 + if( result[ result.length - 1 ].passage.replace( /\s/g, '' ) !== searchResult.passage.replace( /\s/g, '' ) ) {
68 + result.push( searchResult );
69 + }
70 + }
71 +}
68 72
69 const getHtmlMain = ( main, keywordText, html, defaultURL, findSearchResult ) => { 73 const getHtmlMain = ( main, keywordText, html, defaultURL, findSearchResult ) => {
70 const $ = cheerio.load( html ); 74 const $ = cheerio.load( html );
...@@ -94,6 +98,9 @@ search.naver = ( keywordText ) => { ...@@ -94,6 +98,9 @@ search.naver = ( keywordText ) => {
94 result = getHtmlMain( naverMain, keywordText, html, naverURL, naver ); 98 result = getHtmlMain( naverMain, keywordText, html, naverURL, naver );
95 resolve( result ); 99 resolve( result );
96 }) 100 })
101 + .catch( ( err ) => {
102 + throw new Error( err );
103 + });
97 }) 104 })
98 } 105 }
99 106
...@@ -110,6 +117,9 @@ search.google = ( keywordText ) => { ...@@ -110,6 +117,9 @@ search.google = ( keywordText ) => {
110 result = getHtmlMain( googleMain, keywordText, html, googleURL, google ); 117 result = getHtmlMain( googleMain, keywordText, html, googleURL, google );
111 resolve( result ); 118 resolve( result );
112 }) 119 })
120 + .catch( ( err ) => {
121 + throw new Error( err );
122 + });
113 }) 123 })
114 } 124 }
115 125
......