Don't crash on activity handling problems.
authorRoger Braun <roger@rogerbraun.net>
Tue, 1 Aug 2017 10:41:46 +0000 (12:41 +0200)
committerRoger Braun <roger@rogerbraun.net>
Tue, 1 Aug 2017 10:41:46 +0000 (12:41 +0200)
lib/pleroma/web/ostatus/ostatus.ex

index 4187afa9df06bfb809b9c8b08dffa26b45e49e19..d9a5924dc26237ef5874df518a049c985d67b141 100644 (file)
@@ -32,25 +32,34 @@ defmodule Pleroma.Web.OStatus do
       {:xmlObj, :string, verb} = :xmerl_xpath.string('string(/entry/activity:verb[1])', entry)
       Logger.debug("Handling #{verb}")
 
-      case verb do
-        'http://activitystrea.ms/schema/1.0/follow' ->
-          with {:ok, activity} <- FollowHandler.handle(entry, doc), do: activity
-        'http://activitystrea.ms/schema/1.0/share' ->
-          with {:ok, activity, retweeted_activity} <- handle_share(entry, doc), do: [activity, retweeted_activity]
-        'http://activitystrea.ms/schema/1.0/favorite' ->
-          with {:ok, activity, favorited_activity} <- handle_favorite(entry, doc), do: [activity, favorited_activity]
-        _ ->
-          case object_type do
-            'http://activitystrea.ms/schema/1.0/note' ->
-              with {:ok, activity} <- NoteHandler.handle_note(entry, doc), do: activity
-            'http://activitystrea.ms/schema/1.0/comment' ->
-              with {:ok, activity} <- NoteHandler.handle_note(entry, doc), do: activity
-            _ ->
-              Logger.error("Couldn't parse incoming document")
-              nil
-          end
+      try do
+        case verb do
+          'http://activitystrea.ms/schema/1.0/follow' ->
+            with {:ok, activity} <- FollowHandler.handle(entry, doc), do: activity
+          'http://activitystrea.ms/schema/1.0/share' ->
+            with {:ok, activity, retweeted_activity} <- handle_share(entry, doc), do: [activity, retweeted_activity]
+          'http://activitystrea.ms/schema/1.0/favorite' ->
+            with {:ok, activity, favorited_activity} <- handle_favorite(entry, doc), do: [activity, favorited_activity]
+          _ ->
+            case object_type do
+              'http://activitystrea.ms/schema/1.0/note' ->
+                with {:ok, activity} <- NoteHandler.handle_note(entry, doc), do: activity
+              'http://activitystrea.ms/schema/1.0/comment' ->
+                with {:ok, activity} <- NoteHandler.handle_note(entry, doc), do: activity
+              _ ->
+                Logger.error("Couldn't parse incoming document")
+                nil
+            end
+        end
+      rescue
+        e ->
+          Logger.error("Error occured while handling activity")
+          Logger.error(inspect(e))
+          nil
       end
     end)
+    |> Enum.filter(&(&1))
+
     {:ok, activities}
   end