인프런 커뮤니티 질문&답변
에러가 발생하고 뭔가 안되는거같아요...
작성
·
433
1
const result = fetch('https://jsonplaceholder.typicode.com/todos/1');
result;
result.then(function(response){
console.log('실행완료');
}).catch(function (error) {
console.log('에러 발생');
})
Promise {<pending>}
VM36:1 GET https://jsonplaceholder.typicode.com/todos/1 net::ERR_FAILED
(anonymous) @ VM36:1
VM36:8 에러 발생
so?bc=1&origin=chrome-untrusted%3A%2F%2Fnew-tab-page&origin=chrome%3A%2F%2Fnew-tab-page&cn=app&pid=1&spid=243&hl=ko&dm=:1 Error handling response: TypeError: Cannot read property 'always' of undefined
at chrome-extension://cnfngpgfjllafbghaimjcmailafcdhod/releaseDrag.js:90:49
const result = fetch('https://jsonplaceholder.typicode.com/todos/1');
VM118:1 Uncaught SyntaxError: Identifier 'result' has already been declared
result
Promise {<rejected>: TypeError: Failed to fetch}__proto__: Promise[[PromiseState]]: "rejected"[[PromiseResult]]: TypeError: Failed to fetch
result.then(function(response){
console.log('실행완료');
}).catch(function (error) {
console.log('에러 발생');
})
VM142:4 에러 발생
Promise {<fulfilled>: undefined}
에러가 발생하고 Failed to fetch 이렇게 뜨고 뭐가 잘못된건지 모르겠어요...
답변 1
0
안녕하세요 상신님!
현재 코드는 잘 작성하셨습니다. promise객체는 오류가 발생하면 catch 안에 있는 구문이 실행되게 됩니다. 현재 에러 내용을 읽어보면 https://jsonplaceholder.typicode.com/todos/1 이 제대로 접속되지 않아 생기는 문제입니다.
모든 사람들에게 공개된 API이다 보니 가끔 저 jsonplaceholder 서버에서 오류가 나는 경우가 있습니다. 현재 시도해봤을 때 다시 정상적으로 동작하고 있으니 다시 확인 부탁드립니다~!




