React Native Expo [AxiosError: Network Error]

Jayden ·2024년 1월 11일

프로젝트 버전 (package.json)

  • "expo": "~49.0.18",
  • "axios": "^1.6.3",
  • "react-native": "0.72.5",
    ...

npm start / npx expo start로 프로젝트 실행 후

안드로이드 에뮬레이터로 실행했습니다.

로컬(localhost:8081)이 아닌 외부 API로 호출하는데 [AxiosError: Network Error] 에러 발생.

백엔드 console 확인 요청 했는데, 넘어온 request 없다고 말씀하십니다.

const fetchFunction = async () => {
  
  try{
    const {data, status} = await axios.get('https://${API}/${endpoint}', {
        headers : {
         Authorization : 'Bearer ------------' 
        },
        params : {
          pid : '-----------'
        }})



      console.log(data)
      console.log(status)

}

catch(e){
  console.log(e)
}

}

_response: "java.security.cert.CertPathValidatorException: Trust anchor for certification path not found."
이 부분이 문제일것으로 추정.

안드로이드 에뮬레이터 대신에 브라우저에서 실행했습니다.

http://localhost:19006으로 실행.

정상적으로 데이터를 불러 옵니다.

https 요청으로 인한 이슈일 가능성도 의심이 되어

News API로 테스트했습니다.

https://newsapi.org/

const fetchFunction = async () => {
  
  try{
 

  const {data, status} = await axios.get(`https://newsapi.org/v2/everything?q=tesla&from=2023-12-11&
                                          sortBy=publishedAt&apiKey=a59be9aa893d41d6844304d4c23162ef`)

      console.log(data)
      console.log(status)

}

catch(e){
  console.log(e)
}

}

데이터가 정상적으로 잘 불러와 집니다.

profile
프론트엔드 개발자

0개의 댓글