Skip to content

Commit

Permalink
Some fixes and logging
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigo-o committed Oct 15, 2024
1 parent a18768f commit dd3c1bb
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/beacon_api/controllers/error_controller.ex
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
defmodule BeaconApi.ErrorController do
require Logger
use BeaconApi, :controller

@spec bad_request(Plug.Conn.t(), binary()) :: Plug.Conn.t()
def bad_request(conn, message) do
Logger.error("Bad request: #{message}, path: #{conn.request_path}")
conn
|> put_status(400)
|> json(%{
Expand All @@ -13,6 +15,7 @@ defmodule BeaconApi.ErrorController do

@spec not_found(Plug.Conn.t(), any) :: Plug.Conn.t()
def not_found(conn, _params) do
Logger.error("Not found resource, path: #{conn.request_path}")
conn
|> put_status(404)
|> json(%{
Expand All @@ -23,6 +26,7 @@ defmodule BeaconApi.ErrorController do

@spec internal_error(Plug.Conn.t(), any) :: Plug.Conn.t()
def internal_error(conn, _params) do
Logger.error("Internal server error, path: #{conn.request_path}")
conn
|> put_status(500)
|> json(%{
Expand Down
2 changes: 1 addition & 1 deletion lib/beacon_api/controllers/v1/beacon_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ defmodule BeaconApi.V1.BeaconController do
conn
|> json(%{
"data" => %{
"genesis_time" => StoreDb.fetch_genesis_time!(),
"genesis_time" => StoreDb.fetch_genesis_time!() |> Integer.to_string(),
"genesis_validators_root" =>
ChainSpec.get_genesis_validators_root() |> Utils.hex_encode(),
"genesis_fork_version" => ChainSpec.get("GENESIS_FORK_VERSION") |> Utils.hex_encode()
Expand Down
6 changes: 6 additions & 0 deletions lib/beacon_api/controllers/v1/node_controller.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
defmodule BeaconApi.V1.NodeController do
use BeaconApi, :controller

require Logger
alias BeaconApi.ApiSpec
alias BeaconApi.Utils
alias LambdaEthereumConsensus.Beacon.SyncBlocks
Expand Down Expand Up @@ -28,6 +29,7 @@ defmodule BeaconApi.V1.NodeController do

@spec health(Plug.Conn.t(), any) :: Plug.Conn.t()
def health(conn, _params) do
Logger.info("NODE: Health check")
%{is_syncing: syncing?} = SyncBlocks.status()
syncing_status = if syncing?, do: 206, else: 200

Expand All @@ -38,6 +40,7 @@ defmodule BeaconApi.V1.NodeController do

@spec identity(Plug.Conn.t(), any) :: Plug.Conn.t()
def identity(conn, _params) do
Logger.info("NODE: Identity check")
metadata = Metadata.get_metadata() |> Utils.to_json()

%{
Expand All @@ -61,6 +64,7 @@ defmodule BeaconApi.V1.NodeController do

@spec version(Plug.Conn.t(), any) :: Plug.Conn.t()
def version(conn, _params) do
Logger.info("NODE: Version check")
version = Application.spec(:lambda_ethereum_consensus)[:vsn]
arch = :erlang.system_info(:system_architecture)

Expand All @@ -74,6 +78,7 @@ defmodule BeaconApi.V1.NodeController do

@spec syncing(Plug.Conn.t(), any) :: Plug.Conn.t()
def syncing(conn, _params) do
Logger.info("NODE: Syncing check")
%{
is_syncing: is_syncing,
is_optimistic: is_optimistic,
Expand All @@ -93,6 +98,7 @@ defmodule BeaconApi.V1.NodeController do

@spec peers(Plug.Conn.t(), any) :: Plug.Conn.t()
def peers(conn, _params) do
Logger.info("NODE: Peers check")
# TODO: (#1325) This is a stub.
conn
|> json(%{
Expand Down

0 comments on commit dd3c1bb

Please sign in to comment.