Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/design-patterns/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Elixir 使用苦艾酒时从Guardian错误处理程序发送graphql响应_Elixir_Graphql_Phoenix Framework_Absinthe_Guardian - Fatal编程技术网

Elixir 使用苦艾酒时从Guardian错误处理程序发送graphql响应

Elixir 使用苦艾酒时从Guardian错误处理程序发送graphql响应,elixir,graphql,phoenix-framework,absinthe,guardian,Elixir,Graphql,Phoenix Framework,Absinthe,Guardian,我有一个菲尼克斯应用程序与苦艾酒的Graphql API Guardian用于验证在标头中提供承载令牌的请求。在提供无效令牌之前,这一切都非常有效。我在Guardian管道中指定了一个错误处理程序,它当前只响应401 http响应: def auth_error(conn, {type, _reason}, _opts) do body = to_string(type) conn |> put_resp_content_type("text/plain")

我有一个菲尼克斯应用程序与苦艾酒的Graphql API

Guardian用于验证在标头中提供承载令牌的请求。在提供无效令牌之前,这一切都非常有效。我在Guardian管道中指定了一个错误处理程序,它当前只响应401 http响应:

def auth_error(conn, {type, _reason}, _opts) do
    body = to_string(type)

    conn
    |> put_resp_content_type("text/plain")
    |> send_resp(401, body)
end
这对任何graphql客户机都不友好,我的解析器并不真正关心令牌是否无效,因为他们有自己的检查来查看上下文中是否提供了用户


如果令牌无效,有没有办法从错误处理程序继续执行管道,这样我就可以给出正确的graphql响应?

我的建议是创建一个插件来验证承载令牌并在上下文中设置当前用户。然后,您可以编写一个absithe.Middleware来验证当前用户是否存在,如果不存在,则设置一个错误

此外,还可以查看更好的错误