身份验证在承诺中未被捕获

时间:2017-09-07 05:46:35

标签: feathersjs

我生成了一个新的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中的同一文件基本相同。

我必须做些什么来捕捉我的浏览器声称我不是的例外?

1 个答案:

答案 0 :(得分:0)

当我实际创建用户时,问题不再发生。我

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

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