Promise 中未捕获的身份验证

Authentication Uncaught in Promise

我生成了一个新的 Feathers 应用程序,然后生成了身份验证。我还没有编辑任何代码。

我使用 create-react-app 生成了一个 React 客户端,对此我所做的唯一更改是我创建了一个尝试对用户进行身份验证的登录组件:

import React, { Component } from 'react';
import client from './feathers';

export default class Login extends Component {
  constructor(props) {
    super(props);
    this.state = {};
  }

  componentDidMount() {
    client.authenticate({
      strategy: 'local',
      email: 'feathers@example.com',
      password: 'secret'
    }).then(token => {
      this.setState({ login: true });
    }).catch(error => {
      console.log(error);
      this.setState({ login: false });
    });
  }

  render() {
    if (this.state.login === undefined) {
      return <p>Logging in...</p>;
    } else if (this.state.login === true) {
      return <p>Logged in!</p>;
    } else {
      return <p>Not logged in.</p>;
    }
  }
}

登录组件按预期运行,但我的浏览器声称我没有在 Promise 中捕获以下异常:

{type: "FeathersError", name: "NotAuthenticated", message: "Invalid login", code: 401, className: "not-authenticated", …}

catch 块中记录了相同的异常。

./feathersdaffl's feathers-chat-react.

中的同一文件基本相同

我必须怎么做才能捕获我的浏览器声称我不是的异常?

当我实际创建用户时,问题不再出现。我

  • 创建了一个用户
  • 登录成功
  • 试图以不存在的用户身份登录。

当我执行最后一步时,验证 Promise 按预期被拒绝,但我的浏览器不再声称我没有捕获异常。