Repository: tallarium/reverse_proxy_plug (elixir)

Issue:
Error callback can be simplified
It will be a breaking change, but there is no reason for the `opts[:error_callback]` to pass `{:error, error}` through from `response/3` - we should pattern match in the function head and pass `error` through to the callback instead.

Pull request description:
no need to pass entire tuple to error callbacks
fixes #182 

Patch:
diff --git a/lib/reverse_proxy_plug.ex b/lib/reverse_proxy_plug.ex
index 9436013..72ede92 100644
--- a/lib/reverse_proxy_plug.ex
+++ b/lib/reverse_proxy_plug.ex
@@ -119,7 +119,7 @@ defmodule ReverseProxyPlug do
     process_response(opts[:response_mode], conn, resp, opts)
   end
 
-  def response(error, conn, opts) do
+  def response({:error, error}, conn, opts) do
     do_error_callback(opts[:error_callback], error, conn)
   end
 
@@ -156,7 +156,7 @@ defmodule ReverseProxyPlug do
     |> Conn.send_resp()
   end
 
-  defp status_from_error({:error, %HTTPClient.Error{id: nil, reason: reason}})
+  defp status_from_error(%HTTPClient.Error{id: nil, reason: reason})
        when reason in @timeout_error_reasons do
     :gateway_timeout
   end


Test patch:
diff --git a/test/reverse_proxy_plug_test.exs b/test/reverse_proxy_plug_test.exs
index 7bf091a..5e231b6 100644
--- a/test/reverse_proxy_plug_test.exs
+++ b/test/reverse_proxy_plug_test.exs
@@ -333,12 +333,12 @@ defmodule ReverseProxyPlugTest do
   end
 
   defmodule ErrorHandling do
-    def mfa_error_callback(arg, {:error, error}) do
+    def mfa_error_callback(arg, error) do
       send(self(), {:got_arg, arg})
       send(self(), {:got_error, error})
     end
 
-    def mfa_error_callback(arg, {:error, error}, conn) do
+    def mfa_error_callback(arg, error, conn) do
       send(self(), {:got_arg, arg})
       send(self(), {:got_error, error})
       send(self(), {:got_conn, conn})
@@ -347,11 +347,11 @@ defmodule ReverseProxyPlugTest do
 
     def mfa_error_callback1(arg, error), do: mfa_error_callback(arg, error)
 
-    def fun_error_callback({:error, error}) do
+    def fun_error_callback(error) do
       send(self(), {:got_error, error})
     end
 
-    def fun_error_callback({:error, error}, conn) do
+    def fun_error_callback(error, conn) do
       send(self(), {:got_error, error})
       send(self(), {:got_conn, conn})
       resp(conn, :internal_server_error, "internal server error")