Предупреждение Bluebird — обещание было создано в обработчике, но не было возвращено из него

Во-первых, я знаю, что я должен вернуть обещания, чтобы избежать этого предупреждения. Я также пытался вернуть null, как было предложено здесь, но это не работает. Это мой кусок кода:

import React, { Component } from 'react';
import request from 'superagent-bluebird-promise';

function loadCountry(url, countryId) {
  return request.get(`${url}/countries/${countryId}`).set('Accept', 'application/json').
    then(response => response.body.name || response.body.id).catch(errors => null);
}

class AddressCountry extends Component {

  ...

  componentDidMount() {
    loadCountry(this.props.actionUrl, this.props.countryId).then(country => {
      this.setState({ country: country });
    });
  }
}

Я пытался вернуть null после строки this.setState({ country: country });, но это не сработало. Это ошибка, которую я получаю:

Warning: a promise was created in a handler at eval at <anonymous> (http://localhost:8080/supplier/static/bundle.js:1201:1), <anonymous>:65:16 but was not returned from it
    at new Promise (eval at <anonymous> (http://localhost:8080/supplier/static/bundle.js:2064:1), <anonymous>:2715:26)
    at <anonymous>
From previous event:
    at Request.promise (eval at <anonymous> (http://localhost:8080/supplier/static/bundle.js:728:1), <anonymous>:72:10)
    at loadCountry (eval at <anonymous> (http://localhost:8080/supplier/static/bundle.js:4762:1), <anonymous>:25:157)
    at AddressCountry.componentDidMount (eval at <anonymous> (http://localhost:8080/supplier/static/bundle.js:4762:1), <anonymous>:51:7)
    at measureLifeCyclePerf (eval at <anonymous> (http://localhost:8080/supplier/static/bundle.js:3959:1), <anonymous>:77:12)
    at Object.batchedUpdates (eval at <anonymous> (http://localhost:8080/supplier/static/bundle.js:4078:1), <anonymous>:62:26)
    at enqueueUpdate (eval at <anonymous> (http://localhost:8080/supplier/static/bundle.js:1103:1), <anonymous>:26:16)
    at SupplierAddressEditor.ReactComponent.setState (eval at <anonymous> (http://localhost:8080/supplier/static/bundle.js:1201:1), <anonymous>:65:16)
From previous event:
    at measureLifeCyclePerf (eval at <anonymous> (http://localhost:8080/supplier/static/bundle.js:3959:1), <anonymous>:77:12)
    at Object.batchedUpdates (eval at <anonymous> (http://localhost:8080/supplier/static/bundle.js:4078:1), <anonymous>:62:26)

PS: не дубликат этот вопрос или это


person Lekeasong    schedule 01.06.2017    source источник


Ответы (1)


Вам нужно вернуть обещание из loadCountry() в componentDidMount

componentDidMount() {
        return loadCountry(this.props.actionUrl, this.props.countryId).then(country => this.setState({ country }));
      }
person MunkyJunky    schedule 01.06.2017
comment
Я надел это, но все равно показывает то же предупреждение :( - person Lekeasong; 01.06.2017