从完成的函数中忽略异常

时间:2019-02-17 21:44:24

标签: node.js firebase google-cloud-functions stripe-payments

执行此函数时,我不断收到此错误。

  

忽略已完成功能的异常

我想念什么?

class App extends Component {

    state = {
      result: [],
      name: 'Roger',
      userInput: '',
    }

  handleChange = event=> {
    event.preventDefault();
    this.setState({userInput: event.target.value});
  }

  handleSubmit = event=> {
    event.preventDefault();

    axios.get('http://localhost:4000/search?query=' + this.state.userInput)
      .then(res => {
        var result = res.data;
        this.setState({ result: result });
        console.log(this.state.result);
        console.log(this.state.userInput);
      })

  }

  render() {
    return (
      <div className="App">
        <h2>hello from react</h2>
          <form action="/search">
            <input type="text" value={this.state.userInput} onChange={this.handleChange} placeholder="Search..." name="query" id="userText"/>
            <button type="submit" onClick={this.handleSubmit}><i>Search</i></button>
          </form>
      </div>
    );
  }
}

1 个答案:

答案 0 :(得分:0)

使用try and catch手动记录错误,例如

try {
  //code goes here
}
catch(error) {
  console.log(error)
}