 
   # If results don't exist, and next is not null, serve it
   defp _stream({:ok, %{"next" => next, "results" => _}}) do
-    [ core, params ] = String.split(next, "?")
-    case get(core, [query: Query.decode(params)]).body do
-      {:ok, %{ "next" => next, "results" => [ head | tail] }} ->
+    [core, params] = String.split(next, "?")
+    case get(core, [query: Plug.Conn.Query.decode(params)]).body do
+      {:ok, %{"next" => next, "results" => [head | tail]}} ->
         {head, {:ok, %{"next" => next, "results" => tail}}}
       true ->
         nil
     end
+  end
+
+  defp _stream({:error, message}) do
+    message
   end
 
   # Wrap it all

  # -----------------------------------

  # If results exist, send them, passing only the tail
  defp _stream({:ok, %{"next" => next, "results" => [ head | tail ]}}) do
    {head, {:ok, %{"next" => next, "results" => tail}}}
  end



  @nb_slug Application.get_env(:core, :nb_slug)
  @nb_token Application.get_env(:core, :nb_token)

  @default_params %{
    limit: 100,
    access_token: @nb_token
  }

  defp process_url(url) do
    if String.starts_with? url, "/api/v1" do
      "https://#{@nb_slug}.nationbuilder.com" <> url
    else
      "https://#{@nb_slug}.nationbuilder.com/api/v1/" <> url
    end
  end

