2016-10-11 9 views
0

私は基本的な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)) 
} 

感謝。

答えて

0

他の誰かがこの問題に直面した場合、私はをPromiseチェーンの最後に追加することで修正することができました。

componentDidMount() { 
    axios.get('https://rallycoding.herokuapp.com/api/music_albums') 
    .then((response) => console.log(response)) 
    .done(); 
} 
0

最初の文で応答を返す必要があります。それ以外の場合は、連鎖は機能しません。

componentWillMount() { 
 
    axios.get('http://rallycoding.herokuapp.com/api/music_albums') 
 
     .then((response) => { 
 
      if(!response.ok){ 
 
       console.log(response.statusText); 
 
      } 
 
      console.log((response)) 
 
      
 
      // return response 
 
      return response; 
 
     }).then((response) => { 
 
      console.log("ok") 
 
     }).catch((err) => console.log(err)) 
 
}

この情報がお役に立てば幸いです。

+0

動作しませんでした:-( – Raymond

関連する問題