codestates / codestates/aneun-dongne

[Error Handling Log] 관광지 세부정보 페이지(서버)에서 외부 api 응답이 너무 늦게 호출되어 클라이언트에 전달하려는 data 객체에 content와 homepage 정보를 추가하지 못하는 에러/손승이

Open
#96 1 comment 0 reactions 0 assignees View on GitHub
Error Handling Log server
Dominant language
JavaScript
Stars
6
Forks
7
PR merge metrics
No merged PRs in 30d

Description

> ### 어떤 에러인가요?
> 관광지 세부정보 페이지(서버)에서 아직 content와 homepage가 등록되지 않은 포스트 한정으로 외부 api(한국관광공사)에서 정보를 불러와 해당 데이터를 추가하고(함수 updatepostData()) 그 결과를 리턴(함수 getPostData())해야 하는데 async/await 비동기함수로 순서를 정해 주었음에도 두 함수의 순서가 뒤바뀌어서 결과값이 리턴된 이후 db가 업데이트되는 오류
> ```shell
> await updatepostData(126535);
> console.log(await getPostData(1, 126535));
> ```
> 위 코드처럼 순서를 정해주었으나 소용이 없었다.
> ### 에러 핸들링 방법
> 서버에서 외부 api로 요청을 보내 응답 데이터를 저장할 때 기존에 request 모듈을 이용하였다.
> 하지만 이 모듈이 유독 async/await 가 잘 먹히지 않는 방식인 것 같아서 request 대신 axios를 써 보기로 하였다.
> -> 해결
> ```js
> try {
> const response = await axios.get(
> `http://api.visitkorea.or.kr/openapi/service/rest/KorService/detailCommon?ServiceKey=${process.env.REACT_APP_TOUR_API_KEY}&contentTypeId=12&contentId=${contentId}&MobileOS=ETC&MobileApp=TourAPI3.0_Guide&defaultYN=Y&firstImageYN=Y&areacodeYN=Y&catcodeYN=Y&addrinfoYN=Y&mapinfoYN=Y&overviewYN=Y&transGuideYN=Y&_type=json`
> );
> if (prevPost.post_content === null || prevPost.post_homepage_path === null) {
> await Post.update(
> {
> post_content: response.data.response.body.items.item.overview,
> post_homepage_path: response.data.response.body.items.item.homepage,
> },
> { where: { post_contentid: contentId } }
> );
> console.log("저장 완료");
> } else {
> console.log("이미 저장됨");
> }
> } catch (err) {
> console.log(err);
> }
> ```
> ```js
> await updatepostData(126535).then(async () => {
> console.log(await getPostData(1, 126535));
> });
> ```
> 함수가 알맞은 순서로 잘 실행되는 것을 확인

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by locating the server-side tourist-detail flow and the updatepostData() and getPostData() functions. Review the external Korea Tourism API request and confirm that the data update completes before getPostData() returns the post. Done means posts missing content or homepage receive the fetched values before the response is returned.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
api, backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.