无效的凭据在auth突变时引发异常

时间:2019-07-15 22:41:31

标签: python django graphql graphene-django

我在django项目中使用了graphene-django和django-graphql-jwt。当我设置无效凭据时,服务器会引发“无效凭据”异常。

是否应该使用无效的凭据在服务器上引发异常?当我用错误的数据测试tokenAuth突变时,Django服务器会引发异常。

Django服务器日志:

  File "/Users/cgf/.local/share/virtualenvs/testdjangoauthbackend-183R1gMP/lib/python3.7/site-packages/promise/promise.py", line 487, in _resolve_from_executor
    executor(resolve, reject)
  File "/Users/cgf/.local/share/virtualenvs/testdjangoauthbackend-183R1gMP/lib/python3.7/site-packages/promise/promise.py", line 754, in executor
    return resolve(f(*args, **kwargs))
  File "/Users/cgf/.local/share/virtualenvs/testdjangoauthbackend-183R1gMP/lib/python3.7/site-packages/graphql/execution/middleware.py", line 75, in make_it_promise
    return next(*args, **kwargs)
  File "/Users/cgf/.local/share/virtualenvs/testdjangoauthbackend-183R1gMP/lib/python3.7/site-packages/graphql_jwt/decorators.py", line 106, in wrapper
    result = f(cls, root, info, **kwargs)
  File "/Users/cgf/.local/share/virtualenvs/testdjangoauthbackend-183R1gMP/lib/python3.7/site-packages/graphql_jwt/decorators.py", line 89, in wrapper
    _('Please, enter valid credentials'))
graphql.error.located_error.GraphQLLocatedError: Please, enter valid credentials

2 个答案:

答案 0 :(得分:1)

我也经历过同样的事情。实际上,他们故意显示堆栈跟踪。我认为,这个问题将很快得到解决。请查看this thread了解详细信息。

答案 1 :(得分:0)

django-graphql-auth扩展了django-graphql-jwt以添加更多功能,例如注册,电子邮件验证...

优点之一是它返回包含successerrors的标准输出。

例如,它不会返回错误(例如在django-graphql-jwt中针对无效凭据),而是返回:

{
  "data": {
    "tokenAuth": {
      "success": false,
      "errors": {
        "nonFieldErrors": [
          {
            "message": "Please, enter valid credentials.",
            "code": "invalid_credentials"
          }
        ]
      },
      "token": null,
      "refreshToken": null,
      "unarchiving": false,
      "user": null
    }
  }
}