Skip to content

Commit

Permalink
chore: add fallback controller handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
Ziinc committed Dec 19, 2023
1 parent 82c2be1 commit 6ec4874
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/logflare_web/controllers/api/fallback_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,14 @@ defmodule LogflareWeb.Api.FallbackController do
|> put_status(:not_found)
|> json(%{error: "Not Found"})
end

def call(conn, {:error, msg}) when is_atom(msg) do
call(conn, {:error, Atom.to_string(msg)})
end

def call(conn, {:error, msg}) when is_binary(msg) do
conn
|> put_status(400)
|> json(%{error: msg})
end
end
4 changes: 4 additions & 0 deletions lib/logflare_web/controllers/api/query_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,8 @@ defmodule LogflareWeb.Api.QueryController do
json(conn, %{result: rows})
end
end

def query(_conn, _params) do
{:error, "No query params provided. Supported query params are sql=, bq_sql=, and pg_sql="}
end
end
8 changes: 8 additions & 0 deletions test/logflare_web/controllers/api/query_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ defmodule LogflareWeb.Api.QueryControllerTest do
{:ok, user: user}
end


test "no query param provided", %{conn: conn, user: user} do
conn
|> add_access_token(user, ~w(private))
|> get(~p"/api/query")
|> json_response(400)
end

describe "query with bq" do
setup do
stub(Goth, :fetch, fn _mod -> {:ok, %Goth.Token{token: "auth-token"}} end)
Expand Down

0 comments on commit 6ec4874

Please sign in to comment.