Skip to content

Commit

Permalink
Follow Twitter API which again changed the message for already retwee…
Browse files Browse the repository at this point in the history
…ted error (#890)
  • Loading branch information
knu authored and sferik committed Jun 12, 2018
1 parent b45d545 commit c9bf100
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
21 changes: 15 additions & 6 deletions lib/twitter/error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,21 @@ class Error < StandardError
504 => Twitter::Error::GatewayTimeout,
}.freeze

FORBIDDEN_MESSAGES = {
'Status is a duplicate.' => Twitter::Error::DuplicateStatus,
'You have already favorited this status.' => Twitter::Error::AlreadyFavorited,
'You have already retweeted this tweet.' => Twitter::Error::AlreadyRetweeted,
'sharing is not permissible for this status (Share validations failed)' => Twitter::Error::AlreadyRetweeted,
}.freeze
FORBIDDEN_MESSAGES = proc do |message|
case message
when /(?=.*status).*duplicate/i
# - "Status is a duplicate."
Twitter::Error::DuplicateStatus
when /already favorited/i
# - "You have already favorited this status."
Twitter::Error::AlreadyFavorited
when /already retweeted|Share validations failed/i
# - "You have already retweeted this Tweet." (Nov 2017-)
# - "You have already retweeted this tweet." (?-Nov 2017)
# - "sharing is not permissible for this status (Share validations failed)" (-? 2017)
Twitter::Error::AlreadyRetweeted
end
end

# If error code is missing see https://dev.twitter.com/overview/api/response-codes
module Code
Expand Down
2 changes: 1 addition & 1 deletion spec/fixtures/already_retweeted.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"errors":"You have already retweeted this tweet."}
{"errors":"You have already retweeted this Tweet."}

0 comments on commit c9bf100

Please sign in to comment.