Skip to content

Commit

Permalink
Add logs about errors during adding peer
Browse files Browse the repository at this point in the history
  • Loading branch information
Rados13 committed May 10, 2024
1 parent 5a96434 commit bd719a0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
22 changes: 18 additions & 4 deletions lib/jellyfish_web/controllers/peer_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ defmodule JellyfishWeb.PeerController do
use JellyfishWeb, :controller
use OpenApiSpex.ControllerSpecs

require Logger

alias Jellyfish.Peer
alias Jellyfish.Room
alias Jellyfish.RoomService
Expand Down Expand Up @@ -65,6 +67,9 @@ defmodule JellyfishWeb.PeerController do
]

def create(conn, %{"room_id" => room_id} = params) do
# TODO: change to debug
Logger.info("Start adding peer in room: #{room_id}")

# the room may crash between fetching its
# pid and adding a new peer to it
# in such a case, the controller will fail
Expand All @@ -86,16 +91,25 @@ defmodule JellyfishWeb.PeerController do
|> render("show.json", assigns)
else
:error ->
{:error, :bad_request, "Invalid request body structure"}
msg = "Invalid request body structure"
Logger.warning(msg)

{:error, :bad_request, msg}

{:error, :invalid_type} ->
{:error, :bad_request, "Invalid peer type"}
msg = "Invalid peer type"
Logger.warning(msg)
{:error, :bad_request, msg}

{:error, :room_not_found} ->
{:error, :not_found, "Room #{room_id} does not exist"}
msg = "Room #{room_id} does not exist"
Logger.warning(msg)
{:error, :not_found, msg}

{:error, :reached_peers_limit} ->
{:error, :service_unavailable, "Reached peer limit in room #{room_id}"}
msg = "Reached peer limit in room #{room_id}"
Logger.warning(msg)
{:error, :service_unavailable, msg}
end
end

Expand Down
5 changes: 5 additions & 0 deletions lib/jellyfish_web/controllers/room_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ defmodule JellyfishWeb.RoomController do
use JellyfishWeb, :controller
use OpenApiSpex.ControllerSpecs

require Logger

alias Jellyfish.Room
alias Jellyfish.RoomService
alias JellyfishWeb.ApiSpec
Expand Down Expand Up @@ -74,6 +76,9 @@ defmodule JellyfishWeb.RoomController do
end

def create(conn, params) do
# TODO: change to debug
Logger.info("Start creating room")

with {:ok, config} <- Room.Config.from_params(params),
{:ok, room, jellyfish_address} <- RoomService.create_room(config) do
conn
Expand Down

0 comments on commit bd719a0

Please sign in to comment.