작성
·
45
0
axios를 create할때 timeout값을
1초(1000)에서 10초(10000)로
변경했습니다.
api 서버를 종료하고 테스트 해보니
10초가 안먹는거 같네요.
다른 값으로 입력해도 거의 항상 2초만에
network error가 뜹니다.
왜 그런걸까요?
import axios from 'axios';
function create(baseURL) {
const instance = axios.create({
baseURL,
timeout: 10000,
headers: { 'X-Custom-Header': 'foobar' },
});
return instance;
}
답변 3
1
안녕하세요.
api 서버를 꺼버리고 테스트 했을때도
timeout 시간동안 계속 시도하는걸로 이해했는데
그게 아니었네요.
api 서버에서 의도적으로 11초의 delay를 주니
정상적인 timeout error가 발생한것을 확인했습니다.
빠르고 정확한 답변에 감사드립니다.
0
안녕하세요.
console로 찍어보니 아래와 같습니다.
AxiosError {message: 'Network Error', name: 'AxiosError', code: 'ERR_NETWORK', config: {…}, request: XMLHttpRequest, …}
code: "ERR_NETWORK"
config:
adapter: (3) ['xhr', 'http', 'fetch']
allowAbsoluteUrls: true
baseURL: "http://localhost:58824/api/post"
data: undefined
env: {FormData: ƒ, Blob: ƒ}
headers: AxiosHeaders {Accept: 'application/json, text/plain, /', Content-Type: undefined, X-Custom-Header: 'foobar'}
maxBodyLength: -1
maxContentLength: -1
method: "get"
timeout: 10000
transformRequest: [ƒ]
transformResponse: [ƒ]
transitional: {silentJSONParsing: true, forcedJSONParsing: true, clarifyTimeoutError: false}
url: "?group=1&page=1"
validateStatus: ƒ validateStatus(status)
xsrfCookieName: "XSRF-TOKEN"
xsrfHeaderName: "X-XSRF-TOKEN"
[[Prototype]]: Object
message: "Network Error"
name: "AxiosError"
request: XMLHttpRequest {onreadystatechange: null, readyState: 4, timeout: 10000, withCredentials: false, upload: XMLHttpRequestUpload, …}
stack: "AxiosError: Network Error\n at XMLHttpRequest.handleError (http://localhost:3000/node_modules/.vite/deps/axios.js?v=597761da:1542:14)\n at Axios.request (http://localhost:3000/node_modules/.vite/deps/axios.js?v=597761da:2062:41)\n at async fetchPosts (http://localhost:3000/src/components/PostListComponent.vue?t=1745193941392:39:22)"
[[Prototype]]: Error
0
axios timeout 에러가 아닌것으로 보입니다.
axios timeout 에러는 HTTP 요청이 설정된 시간 내에 완료되지 않았을 때 발생하는 에러입니다. 이러한 에러는 일반적으로
에러 코드: 보통
ECONNABORTED
가 표시됩니다 (앞서 본ERR_NETWORK
와 다름)메시지: "timeout of X ms exceeded" 같은 메시지가 포함됩니다
설정된 timeout 값(밀리초 단위)보다 요청 처리 시간이 길어질 때 발생합니다
아래 내용을 확인해보세요
프론트엔드는 3000번 포트에서 실행 중이고, 백엔드는 58824번 포트에서 실행 중인 것으로 보입니다.
백엔드 서버(58824 포트)가 실행 중인지 확인하세요
서버의 API 엔드포인트가 정확한지 확인하세요
API 요청 경로가 올바른지 확인하세요
개발자 도구의 네트워크 탭에서 해당 요청의 상세 정보를 확인해보세요