Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(server) - improve error handling and logging #46

Merged
merged 1 commit into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion server/lib/publisher/wordpress/episode.ex
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ defmodule Publisher.WordPress.Episode do
{:ok, id} ->
[id | acc]
{:error, reason} ->
Logger.info("Couldn't create a contributor: #{reason}")
Logger.info("Couldn't create a contributor: #{inspect(reason)}")
acc
end

Expand Down
24 changes: 18 additions & 6 deletions server/lib/publisher_web/controllers/api.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
defmodule PublisherWeb.Controllers.API do
require Logger

import Plug.Conn
import PublisherWeb.Controllers.Controller, only: [json: 2]

Expand Down Expand Up @@ -26,7 +28,9 @@ defmodule PublisherWeb.Controllers.API do
with_validation(conn, headers_to_map(headers), Validator.WordPressSiteHeader, fn conn, data ->
case Podcast.feed_url(data."wordpress-site") do
{:ok, data} -> json(conn, data)
{:error, reason} -> send_resp(conn, 400, "Error: #{reason}")
{:error, reason} ->
Logger.error("podcast_feed_url doesnot work reason: #{inspect(reason)}")
send_resp(conn, 400, "Error: Podcast.feed_url")
end
end)
end
Expand All @@ -35,7 +39,9 @@ defmodule PublisherWeb.Controllers.API do
with_validation(conn, headers_to_map(headers), Validator.WordPressAuthHeaders, fn conn, _ ->
case Podcast.set_settings(headers, body) do
:ok -> json(conn, %{})
{:error, reason} -> send_resp(conn, 400, "Error: #{reason}")
{:error, reason} ->
Logger.error("podcast_set_settings reason: #{inspect(reason)}")
send_resp(conn, 400, "Error: Podcast.set_settings")
end
end)
end
Expand All @@ -45,7 +51,9 @@ defmodule PublisherWeb.Controllers.API do
with_validation(conn, body, Validator.SavePodcast, fn conn, body_data ->
case Podcast.save_podcast_data(headers, body_data) do
{:ok, data} -> json(conn, data)
{:error, reason} -> send_resp(conn, 400, "Error: #{reason}")
{:error, reason} ->
Logger.error("podcast_save_data reason: #{inspect(reason)}")
send_resp(conn, 400, "Error: Podcast.save_podcast_data")
end
end)
end)
Expand All @@ -56,7 +64,9 @@ defmodule PublisherWeb.Controllers.API do
with_validation(conn, body, Validator.SavePodcastImage, fn conn, body_data ->
case Podcast.save_podcast_image(headers, body_data) do
{:ok, info} -> json(conn, info)
{:error, reason} -> send_resp(conn, 400, "Error: #{reason}")
{:error, reason} ->
Logger.error("podcast_save_image reason: #{inspect(reason)}")
send_resp(conn, 400, "Error: Podcast.save_podcast_image")
end
end)
end)
Expand All @@ -67,7 +77,9 @@ defmodule PublisherWeb.Controllers.API do
with_validation(conn, body, Validator.CopyPodcastImage, fn conn, body_data ->
case Podcast.copy_podcast_image(headers, body_data) do
{:ok, info} -> json(conn, info)
{:error, reason} -> send_resp(conn, 400, "Error: #{reason}")
{:error, reason} ->
Logger.error("podcast_copy_image reason: #{inspect(reason)}")
send_resp(conn, 400, "Error: Podcast.copy_podcast_image")
end
end)
end)
Expand All @@ -80,7 +92,7 @@ defmodule PublisherWeb.Controllers.API do
with_validation_array(conn, body["chapters"], Validator.SaveChapters, fn conn, _ ->
case Episode.save(conn, body) do
:ok -> json(conn, %{status: "success"})
_ -> send_resp(conn, 400, "Error: unable to save episode")
_ -> send_resp(conn, 400, "Error: unable to save episode")
end
end)
end)
Expand Down
Loading