From b901daa542745d552525335bc6def6b4f59dd95a Mon Sep 17 00:00:00 2001 From: Inhji Date: Tue, 22 Aug 2023 00:07:23 +0200 Subject: [PATCH] fix fetching slug --- lib/chiya_web/indie/micropub.ex | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/lib/chiya_web/indie/micropub.ex b/lib/chiya_web/indie/micropub.ex index c043bc1..df243e7 100644 --- a/lib/chiya_web/indie/micropub.ex +++ b/lib/chiya_web/indie/micropub.ex @@ -41,23 +41,22 @@ defmodule ChiyaWeb.Indie.Micropub do def find_note(note_url) do Logger.info("Looking up note by url #{note_url}") - slug = Chiya.Notes.Note.note_slug(note_url) + case Chiya.Notes.Note.note_slug(note_url) do + {:ok, slug} -> + Logger.info("Found note with slug #{slug}, fetching note.") + note = Chiya.Notes.get_note_by_slug_preloaded(slug) + if is_nil(note) do + Logger.error("Note with #{note_url} was not found.") + {:error, :invalid_request} + else + Logger.info("Note found!") + {:ok, note} + end - if is_nil(slug) do - Logger.error("Note with #{note_url} was not found.") - {:error, :invalid_request} - else - Logger.info("Found note with slug #{slug}, fetching note.") - note = Chiya.Notes.get_note_by_slug_preloaded(slug) - - if is_nil(note) do + _ -> Logger.error("Note with #{note_url} was not found.") {:error, :invalid_request} - else - Logger.info("Note found!") - {:ok, note} - end end end