Fix follow errors
authorRachel H <lastexyle@gmail.com>
Thu, 7 Jun 2018 04:26:44 +0000 (21:26 -0700)
committerRachel H <lastexyle@gmail.com>
Thu, 7 Jun 2018 07:39:24 +0000 (00:39 -0700)
.gitignore
lib/pleroma/web/twitter_api/controllers/util_controller.ex
lib/pleroma/web/web_finger/web_finger.ex

index 3fbf17ba811a19b805ff714d78a9aee6a26559fb..9aad700ee1bd06ca1060ed226dec97aea7bd48db 100644 (file)
@@ -25,4 +25,7 @@ erl_crash.dump
 /config/setup_db.psql
 
 .DS_Store
-.env
\ No newline at end of file
+.env
+
+# Editor config
+/.vscode
\ No newline at end of file
index cc514656610e8e0b8744aae435be872d2e4e9013..7a0c37ce97f1c8a9eeb04cded61518e7042aeaec 100644 (file)
@@ -189,7 +189,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilController do
              {:ok, follower} <- User.follow(follower, followed) do
           ActivityPub.follow(follower, followed)
         else
-          _e -> Logger.debug("follow_import: following #{account} failed")
+          err -> Logger.debug("follow_import: following #{account} failed with #{inspect(err)}")
         end
       end)
     end)
index 0b417479d069a59b3c0950b75d3870f2ffc075b7..e7ee810f9993100320c3727fdae84a4adc904d3d 100644 (file)
@@ -144,41 +144,50 @@ defmodule Pleroma.Web.WebFinger do
     end
   end
 
-  defp webfinger_from_xml(doc) do
-    magic_key = XML.string_from_xpath(~s{//Link[@rel="magic-public-key"]/@href}, doc)
+  defp get_magic_key(magic_key) do
     "data:application/magic-public-key," <> magic_key = magic_key
+    {:ok, magic_key}
+  rescue
+    MatchError -> {:error, "Missing magic key data."}
+  end
 
-    topic =
-      XML.string_from_xpath(
-        ~s{//Link[@rel="http://schemas.google.com/g/2010#updates-from"]/@href},
-        doc
-      )
-
-    subject = XML.string_from_xpath("//Subject", doc)
-    salmon = XML.string_from_xpath(~s{//Link[@rel="salmon"]/@href}, doc)
-
-    subscribe_address =
-      XML.string_from_xpath(
-        ~s{//Link[@rel="http://ostatus.org/schema/1.0/subscribe"]/@template},
-        doc
-      )
-
-    ap_id =
-      XML.string_from_xpath(
-        ~s{//Link[@rel="self" and @type="application/activity+json"]/@href},
-        doc
-      )
-
-    data = %{
-      "magic_key" => magic_key,
-      "topic" => topic,
-      "subject" => subject,
-      "salmon" => salmon,
-      "subscribe_address" => subscribe_address,
-      "ap_id" => ap_id
-    }
+  defp webfinger_from_xml(doc) do
+    with magic_key <- XML.string_from_xpath(~s{//Link[@rel="magic-public-key"]/@href}, doc),
+         {:ok, magic_key} <- get_magic_key(magic_key),
+         topic <-
+           XML.string_from_xpath(
+             ~s{//Link[@rel="http://schemas.google.com/g/2010#updates-from"]/@href},
+             doc
+           ),
+         subject <- XML.string_from_xpath("//Subject", doc),
+         salmon <- XML.string_from_xpath(~s{//Link[@rel="salmon"]/@href}, doc),
+         subscribe_address <-
+           XML.string_from_xpath(
+             ~s{//Link[@rel="http://ostatus.org/schema/1.0/subscribe"]/@template},
+             doc
+           ),
+         ap_id <-
+           XML.string_from_xpath(
+             ~s{//Link[@rel="self" and @type="application/activity+json"]/@href},
+             doc
+           ) do
+      data = %{
+        "magic_key" => magic_key,
+        "topic" => topic,
+        "subject" => subject,
+        "salmon" => salmon,
+        "subscribe_address" => subscribe_address,
+        "ap_id" => ap_id
+      }
 
-    {:ok, data}
+      {:ok, data}
+    else
+      {:error, e} ->
+        {:error, e}
+
+      e ->
+        {:error, e}
+    end
   end
 
   defp webfinger_from_json(doc) do
@@ -268,8 +277,11 @@ defmodule Pleroma.Web.WebFinger do
       if doc != :error do
         webfinger_from_xml(doc)
       else
-        {:ok, doc} = Jason.decode(body)
-        webfinger_from_json(doc)
+        with {:ok, doc} <- Jason.decode(body) do
+          webfinger_from_json(doc)
+        else
+          {:error, e} -> e
+        end
       end
     else
       e ->