私は基本的なJSONデータをフェッチしますが、このエラーを取得の上に保つためにaxiosを使用しています:約束拒否(ネットワークエラー)
Possible unhandled promise rejection (id: 0): Network Error
今そのエラー自体は何が起こっているのかを知って、「同じくらい」有用ではありませんでしたので、コードブロックを変更して.catch
を使用しました。
エラー:
Error: Network Error
at createError (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:82235:11)
at XMLHttpRequest.handleError (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:82107:8)
at XMLHttpRequest.dispatchEvent (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:10284:15)
at XMLHttpRequest.setReadyState (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:25988:6)
at XMLHttpRequest.__didCompleteResponse (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:25836:6)
at http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:25930:52
at RCTDeviceEventEmitter.emit (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:9523:23)
at MessageQueue.__callFunction (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:7339:34)
at http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:7216:8
at guard (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:7155:1)
コード:事前に
componentWillMount() {
axios.get('http://rallycoding.herokuapp.com/api/music_albums')
.then((response) => {
if(!response.ok){
console.log(response.statusText);
}
console.log((response))
}).then((response) => {
console.log("ok")
}).catch((err) => console.log(err))
}
感謝。
動作しませんでした:-( – Raymond