     end
   end
 
-  defp do_multipart_request({:ok, %Response{} = response}, _http, _meta, _path),
-    do: {:error, response}
-
-  defp do_multipart_request({:error, reason}, _http, _meta, _path), do: {:error, reason}
-
-  defp finish_upload({:ok, %Response{status_code: code}}, http, atch_url, meta) when is_2xx(code) do
-    with {:ok, body} <- Poison.encode(%{"attachment_url" => atch_url, "meta" => meta}) do
-      case request(http, :post, "/api/images", body, [], []) do
-        {:ok, %Response{status_code: code} = resp} when is_2xx(code) ->
-          {:ok, resp}
-
-        {:ok, %Response{} = response} ->
-          {:error, response}
-
-        {:error, reason} ->
-          {:error, reason}
-      end
-    end
-  end
-
-  defp finish_upload({:ok, %Response{} = resp}, _http, _url, _meta), do: {:error, resp}
+  defp do_multipart_request({:ok, %Response{} = res}, _, _, _), do: {:error, res}
+
+  defp do_multipart_request({:error, reason}, _, _, _), do: {:error, reason}
+
+  defp finish_upload(
+    {:ok, %Response{status_code: code}},
+    http,
+    atch_url,
+    meta) when is_2xx(code)
+  do
+    case Poison.encode(%{"attachment_url" => atch_url, "meta" => meta}) do
+      {:ok, body} ->
+        case request(http, :post, "/api/images", body, [], []) do
+          {:ok, %Response{status_code: code} = resp} when is_2xx(code) ->
+            {:ok, resp}
+
+          {:ok, %Response{} = response} ->
+            {:error, response}
+
+          {:error, reason} ->
+            {:error, reason}
+        end
+      err -> err
+    end
+  end
+
+  defp finish_upload({:ok, %Response{} = resp}, _, _, _), do: {:error, resp}
   defp finish_upload({:error, reason}, _http, _url, _meta), do: {:error, reason}
 
   # GenServer

    case state.requests[ref] do
      %Buffer{} = buffer ->
        HTTPoison.stream_next(%AsyncResponse{id: ref})
        {:noreply, %{state | requests: %{state.requests | ref => %{buffer | status_code: code}}}}

      nil ->
        {:noreply, state}
    end

    do_normal_request({method, url, body, headers, opts, from}, nil, state)
  end

  defp do_normal_request({_, _, _, _, _, _} = call, file, state) do
    {method, url, body, headers, opts, from} = call
    case HTTPoison.request(method, url, body, headers, opts) do
      {:ok, %HTTPoison.Response{status_code: code, headers: resp_headers}}
      when code in @redirect_status_codes ->
