Don't crash on activity handling problems.

This commit is contained in:
Roger Braun 2017-08-01 12:41:46 +02:00
parent 368fa25f1f
commit c3dfa1970f

View file

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