Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not treat already retweeted/favorited error as failure #2140

Merged
merged 1 commit into from
Oct 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions app/models/agents/twitter_action_agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,21 @@ def receive(incoming_events)
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

Expand Down
21 changes: 18 additions & 3 deletions spec/models/agents/twitter_action_agent_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,30 @@
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
Expand Down