[英]** (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.