Skip to content

Commit

Permalink
Merge pull request #46 from podlove/fix/server-error-handling
Browse files Browse the repository at this point in the history
fix(server) - improve error handling and logging
  • Loading branch information
dnkbln authored Aug 26, 2024
2 parents 60e7096 + 33198f9 commit 925830e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
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

0 comments on commit 925830e

Please sign in to comment.