mirror of
https://github.com/Fishwaldo/huginn.git
synced 2025-03-15 19:31:26 +00:00
Merge pull request #2140 from huginn/ignore_twitter_action_duplicate_error
Do not treat already retweeted/favorited error as failure
This commit is contained in:
commit
509528fd19
2 changed files with 33 additions and 11 deletions
|
@ -63,14 +63,21 @@ module Agents
|
|||
twitter.favorite(tweets) if favorite?
|
||||
twitter.retweet(tweets) if retweet?
|
||||
rescue Twitter::Error => e
|
||||
raise e unless emit_error_events?
|
||||
create_event :payload => {
|
||||
'success' => false,
|
||||
'error' => e.message,
|
||||
'tweets' => Hash[tweets.map { |t| [t.id, t.text] }],
|
||||
'agent_ids' => incoming_events.map(&:agent_id),
|
||||
'event_ids' => incoming_events.map(&:id)
|
||||
}
|
||||
case e
|
||||
when Twitter::Error::AlreadyRetweeted, Twitter::Error::AlreadyFavorited
|
||||
error e.message
|
||||
else
|
||||
raise e unless emit_error_events?
|
||||
end
|
||||
if emit_error_events?
|
||||
create_event payload: {
|
||||
'success' => false,
|
||||
'error' => e.message,
|
||||
'tweets' => Hash[tweets.map { |t| [t.id, t.text] }],
|
||||
'agent_ids' => incoming_events.map(&:agent_id),
|
||||
'event_ids' => incoming_events.map(&:id)
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -109,15 +109,30 @@ describe Agents::TwitterActionAgent do
|
|||
end
|
||||
|
||||
context 'with emit_error_events set to false' do
|
||||
it 'does re-raises the exception on failure' do
|
||||
agent = build_agent
|
||||
let(:agent) { build_agent.tap(&:save!) }
|
||||
|
||||
it 're-raises the exception on failure' do
|
||||
stub(agent.twitter).retweet(anything) {
|
||||
raise Twitter::Error.new('uh oh')
|
||||
}
|
||||
|
||||
expect { agent.receive([@event1]) }.to raise_error(StandardError, /uh oh/)
|
||||
expect { agent.receive([@event1]) }.to raise_error(StandardError, /uh oh/)
|
||||
end
|
||||
|
||||
it 'does not re-raise the exception on "already retweeted" error' do
|
||||
stub(agent.twitter).retweet(anything) {
|
||||
raise Twitter::Error::AlreadyRetweeted.new('You have already retweeted this tweet.')
|
||||
}
|
||||
|
||||
expect { agent.receive([@event1]) }.not_to raise_error
|
||||
end
|
||||
|
||||
it 'does not re-raise the exception on "already favorited" error' do
|
||||
stub(agent.twitter).retweet(anything) {
|
||||
raise Twitter::Error::AlreadyFavorited.new('You have already favorited this status.')
|
||||
}
|
||||
|
||||
expect { agent.receive([@event1]) }.not_to raise_error
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue