Merge pull request #966 from poanetwork/sa-block-getblockreward-api-200-errors

block#getblockreward API returns 200 for errors
853-css-custom-properties
Luke Imhoff 6 years ago committed by GitHub
commit 3a077592ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      apps/block_scout_web/lib/block_scout_web/controllers/api/rpc/block_controller.ex
  2. 24
      apps/block_scout_web/test/block_scout_web/controllers/api/rpc/block_controller_test.exs

@ -14,19 +14,13 @@ defmodule BlockScoutWeb.API.RPC.BlockController do
render(conn, :block_reward, block: block, reward: reward) render(conn, :block_reward, block: block, reward: reward)
else else
{:block_param, :error} -> {:block_param, :error} ->
conn render(conn, :error, error: "Query parameter 'blockno' is required")
|> put_status(400)
|> render(:error, error: "Query parameter 'blockno' is required")
{:error, :invalid} -> {:error, :invalid} ->
conn render(conn, :error, error: "Invalid block number")
|> put_status(400)
|> render(:error, error: "Invalid block number")
{:error, :not_found} -> {:error, :not_found} ->
conn render(conn, :error, error: "Block does not exist")
|> put_status(404)
|> render(:error, error: "Block does not exist")
end end
end end
end end

@ -5,10 +5,10 @@ defmodule BlockScoutWeb.API.RPC.BlockControllerTest do
describe "getblockreward" do describe "getblockreward" do
test "with missing block number", %{conn: conn} do test "with missing block number", %{conn: conn} do
assert response = response =
conn conn
|> get("/api", %{"module" => "block", "action" => "getblockreward"}) |> get("/api", %{"module" => "block", "action" => "getblockreward"})
|> json_response(400) |> json_response(200)
assert response["message"] =~ "'blockno' is required" assert response["message"] =~ "'blockno' is required"
assert response["status"] == "0" assert response["status"] == "0"
@ -17,10 +17,10 @@ defmodule BlockScoutWeb.API.RPC.BlockControllerTest do
end end
test "with an invalid block number", %{conn: conn} do test "with an invalid block number", %{conn: conn} do
assert response = response =
conn conn
|> get("/api", %{"module" => "block", "action" => "getblockreward", "blockno" => "badnumber"}) |> get("/api", %{"module" => "block", "action" => "getblockreward", "blockno" => "badnumber"})
|> json_response(400) |> json_response(200)
assert response["message"] =~ "Invalid block number" assert response["message"] =~ "Invalid block number"
assert response["status"] == "0" assert response["status"] == "0"
@ -29,10 +29,10 @@ defmodule BlockScoutWeb.API.RPC.BlockControllerTest do
end end
test "with a block that doesn't exist", %{conn: conn} do test "with a block that doesn't exist", %{conn: conn} do
assert response = response =
conn conn
|> get("/api", %{"module" => "block", "action" => "getblockreward", "blockno" => "42"}) |> get("/api", %{"module" => "block", "action" => "getblockreward", "blockno" => "42"})
|> json_response(404) |> json_response(200)
assert response["message"] =~ "Block does not exist" assert response["message"] =~ "Block does not exist"
assert response["status"] == "0" assert response["status"] == "0"

Loading…
Cancel
Save