전체 글106 [Front-end] 에러 메시지에 따른 조건부 처리 (err.message) 서버에서 클라이언트로 여러 유형의 에러 메시지를 보내게 됩니다. (500, 404, 401) 그 중 특정 에러를 별도로 처리해야 할 경우가 있습니다. 저는 인증과 관련된 401 에러가 발생했을 경우, 기존 토큰을 삭제하는 코드를 실행시키고자 했습니다. err객체 내의 message 프로퍼티를 활용하여 이를 해결했습니다. (err.message) axios.post(`${process.env.REACT_APP_SERVER_API}/api`, { token: token }) .then(res => { setIsOpened(false) }) .catch(err=>{ if (err.message = "Request failed with status code 401") { dispatch(deleteToken().. 2022. 9. 30. [JavaScript] async/await을 array.map에 사용 시 Promise { <pending> } 에러 array.map 메소드에 async-await을 적용하자 Promise{}에러가 발생했다. // orderList는 주문 데이터가 담긴 배열 const data = await orderList.map(async (order) => { const itemData = await Order_item.findAll({ where: { Order_id: order.id } }) const itemList = itemData.map(el => el.dataValues) order.itemList = itemList return order }) 원인 async 함수는 Promise를 리턴하기 때문에 발생한 에러이다. map 함수가 호출한 async 함수는 Promise를 리턴한다. 그리고 map 함수는 이 Prom.. 2022. 8. 10. [JavaScript] 이중(중첩) 반복문에서 상위 반복문 break/continue JavaScript에서 중첩 반복문(nested loop)을 사용하는 경우가 있습니다. 이중 for문이 그 예시입니다. 중첩 반복문을 사용할 경우 하위 반복문에서 break/continue 사용 시, 하위 반복문에만 그 효과가 적용됩니다. 나아가 여기서는 하위 반복문에서 상위 반복문에 break/continue 효과를 적용하는 방법을 포스팅했습니다. 1. 하위 반복문에서 break/continue 사용 for (let i=0; i 2022. 8. 10. [React] 이벤트핸들러(event handler)에 event 외에 추가 인자 전달하기 이벤트 핸들러(Event Handler)에 합성 이벤트 객체(event) 외에 추가적인 매개변수를 전달하는 방법을 알아보자. 먼저 event 객체만 전달하는 방법부터 살펴보자. 1. event 객체만 전달하기 클릭 2. event 객체 외 다른 매개변수만 전달하기 {eventHandler(parameter)}}> 클릭 3. event 객체와 추가 매개변수를 함께 전달하기 {eventHandler(event, parameter)}}> 클릭 2022. 8. 10. [코딩테스트] Police chase - Queue (JavaScript) 문제 Police officer Daniel has been informed of the location of a suspect and wants to catch him immediately. He starts at a point N on a number line and the suspect is at a point M on the same number line. Police officer has two modes of transportation: walking and teleporting. Walking: Police officer can move from any point X to the point X-1 or X+1 in a single minute. Teleporting: Police office.. 2022. 2. 7. [코딩테스트] sumOfSubOrdinates - DFS (JavaScript) 문제 There is a company in which the relationships of employees are hierarchical. For example, If there is a subordinate B whose boss is A, then B's subordinate C is also a subordinate of A. A HR staff wants to know the total number of subordinates for a specific employee in the company. Complete a function that returns the sum of subordinates of employee from hierarchcy.Each employee cannot be du.. 2022. 2. 7. 이전 1 2 3 4 5 6 7 ··· 18 다음 반응형