简体   繁体   English

**(RuntimeError)预期的操作/ 2返回一个Plug.Conn,所有插件都必须接收一个连接(conn)并返回一个连接

[英]** (RuntimeError) expected action/2 to return a Plug.Conn, all plugs must receive a connection (conn) and return a connection

def create_trans(conn, _params) do

  address = __MODULE__.get_add()
  card = __MODULE__.get_card()

  case Alpha.beta(card, [billing_address: address]) do
    {:ok, result}     -> render conn,"purchase.json",%{purchase: result}
    {:error, reason}  -> render conn,"purchase.json",%{purchase: reason} 
  end

end

The above code gives me the below error, am i missing anything. 上面的代码给了我下面的错误,我错过了什么。

** (RuntimeError) expected action/2 to return a Plug.Conn, all plugs must receive a connection (conn) and return a connection **(RuntimeError)预期的操作/ 2返回一个Plug.Conn,所有插件都必须接收一个连接(conn)并返回一个连接

Maybe provide more informations what Alpha.beta/2 should return. 也许提供更多信息Alpha.beta/2应该返回什么。 Generally your error points that not every scenario is covered in your case block. 通常,您的错误指出case并未涵盖所有情况 Consider using as a last scenario _ , which will match the rest. 考虑将_作为最后一个方案_ ,将与其余方案匹配。

Also you could simply make this code more readable and DRY if you assign result of the Alpha.beta/2 to the variable and then render the result instead of using case , if you basically do the same in both of these scenarios. 另外,如果您将Alpha.beta/2结果分配给变量,然后呈现结果而不使用case ,则可以简单地使此代码更具可读性和DRY, Alpha.beta/2是您基本上在这两种情况下都这样做。

{_, result} = Alpha.beta(card, [billing_address: address)
render(conn, "purchase.json", %{purchase: result}

But in this case you have to be 100% sure that this Alpha.beta/2 returns a tuple, which matches in pattern matching above and according to your issue, it's not so sure. 但是在这种情况下,您必须100%确保此Alpha.beta/2返回一个元组,该元组与上面的模式匹配相匹配,并且根据您的问题,不是很确定。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 (RuntimeError)期望动作/ 2返回一个Plug.Conn,所有插件必须接收连接(conn)并返回连接 - (RuntimeError) expected action/2 to return a Plug.Conn, all plugs must receive a connection (conn) and return a connection expected:action / 2返回Phoenix控制器中的Plug.Conn错误 - expected :action/2 to return a Plug.Conn error in Phoenix controller Elixir从控制器获取错误:预期动作/ 2返回Plug.Conn - Elixir getting error from controller: Expected action/2 to return a Plug.Conn 如何将请求参数填充到 Plug.Conn 连接中? - How to populate request parameters into a Plug.Conn connection? Phoenix:如何在控制台中获得conn%Plug.Conn {} - Phoenix: How to get conn %Plug.Conn{} in the console 从Plug.Conn获取HTTP_REFERRER - Get HTTP_REFERRER from Plug.Conn Phoenix / Elixir:如何使用Plug.Test.conn()在测试连接中设置操作? - Phoenix/Elixir: How to set the action in a test connection with Plug.Test.conn()? 来自 %Plug.Conn{} 远程 IP 的 Phoenix 解析请求主机 - Phoenix Resolve Request Host from %Plug.Conn{} remote ip Phoenix Framework的Plug.Conn中assign和put_session有什么区别? - What is the difference between assign and put_session in Plug.Conn of the Phoenix Framework? 如何使用Plug.Conn读取phoenix控制器中的小块数据 - How to read small chunks of data in phoenix controller, using Plug.Conn
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM