我在我的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发布于 2020-01-15 09:59:16
我也经历了同样的事情。实际上,它们是故意显示堆栈跟踪的。我认为,这个问题很快就会得到解决。有关详细信息,请查看this thread。
发布于 2020-02-06 08:39:26
django-graphql-auth扩展了django-graphql-jwt,添加了更多功能,如注册,电子邮件验证...
它的一个优点是返回一个包含success和errors的标准输出。
例如,它不会引发错误(就像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
}
}
}https://stackoverflow.com/questions/57047996
复制相似问题