다음과 같이 서버에서 항목을 가져 오는 작업 API가 있습니다. 나는이 데이터를 사용하기 위해 React를 사용하고있다. 이제 5__로 시작하는 모든 서버 오류를 포착하고 "인터넷 연결 없음"또는 이와 비슷한 메시지를 표시하려고합니다.React에서 JavaScript (Gateway Timeout) 오류 캐치
export const GetItems = (operand, searchValue) => {
const trimmedValue = searchValue.trim();
let combinedResults;
// make 2 API calls to search on both item_name and code;
// then combine them;
// there is no API method to do this, that I could find
return getItemsByName(operand, trimmedValue)
.then(result => (
(combinedResults = [].concat(result))
))
.then(() => getItemsByCode(operand, trimmedValue))
.then(result => (
(combinedResults = combinedResults.concat(result))
));
};
현재 콘솔에 연결 문제가 있는지 확인해야합니다. @Dane으로 업데이트
그것은 단지 URL을 구축하는 방법을 부르고
const getItemsByCode = (operand, searchValue) => (
FetchToJson(BuildCodeSearchUrl(operand, searchValue))
);
을 요청했다. 모든 것이 잘 작동하고 있다고 생각할 수 있습니다. 연결이 있으면 응답을받습니다.
당신이뿐만 아니라'getItemsByCode'에 대한 코드를 추가시겠습니까? – Dane
와트 http 라이브러리를 사용하고 있습니까? – Panther