Better error upon Tweet embed when Twitter keys missing (#16916)
* complete implementation; specs remain * complete specs * better implementation * more appropriate error msg * ALSO change error msg in spec
This commit is contained in:
parent
b97f49d294
commit
161e18e5df
6 changed files with 33 additions and 15 deletions
|
|
@ -48,6 +48,8 @@ class Tweet < ApplicationRecord
|
|||
retrieve_and_save_tweet(status_id)
|
||||
rescue TwitterClient::Errors::NotFound => e
|
||||
raise e, I18n.t("models.tweet.tweet_not_found")
|
||||
rescue TwitterClient::Errors::BadRequest => e
|
||||
raise e, I18n.t("models.tweet.authentication_error")
|
||||
end
|
||||
|
||||
def retrieve_and_save_tweet(status_id)
|
||||
|
|
|
|||
|
|
@ -11,5 +11,8 @@ module TwitterClient
|
|||
|
||||
class NotFound < ClientError
|
||||
end
|
||||
|
||||
class BadRequest < ClientError
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -27,9 +27,9 @@ en:
|
|||
broadcast:
|
||||
single_active: You can only have one active announcement broadcast
|
||||
comment:
|
||||
deleted: "[deleted]"
|
||||
has_been_deleted: "%{type} has been deleted."
|
||||
hidden: "[hidden by post author]"
|
||||
deleted: '[deleted]'
|
||||
has_been_deleted: '%{type} has been deleted.'
|
||||
hidden: '[hidden by post author]'
|
||||
is_not_valid: is not valid.
|
||||
locked: the discussion is locked on this Post
|
||||
type:
|
||||
|
|
@ -41,7 +41,7 @@ en:
|
|||
one: You cannot mention more than %{count} users in a comment!
|
||||
other: You cannot mention more than %{count} users in a comment!
|
||||
feedback_message:
|
||||
reported: "(you) previously reported this URL."
|
||||
reported: '(you) previously reported this URL.'
|
||||
github_issue:
|
||||
issue_comment_not_found: Issue comment %{issue_id} not found
|
||||
issue_not_found: Issue %{issue_id} not found
|
||||
|
|
@ -58,7 +58,7 @@ en:
|
|||
is_not_valid: is not valid.
|
||||
organization:
|
||||
integer_only: Integer only. No sign allowed.
|
||||
reserved_word: "%<value>s is a reserved word. Contact site admins for help registering your organization."
|
||||
reserved_word: '%<value>s is a reserved word. Contact site admins for help registering your organization.'
|
||||
page:
|
||||
body_must_exist: must exist if body_html or body_json doesn't exist.
|
||||
podcast:
|
||||
|
|
@ -110,11 +110,12 @@ en:
|
|||
unique: can't be an already adjusted tag
|
||||
tweet:
|
||||
tweet_not_found: Tweet not found
|
||||
authentication_error: Authentication error; please contact your Forem admin about possible missing Twitter keys
|
||||
user:
|
||||
could_not_send: confirmation could not be sent. %{e_message}
|
||||
password_not_matched: doesn't match password confirmation
|
||||
has_been_banished: has been banished.
|
||||
is_taken: "%{username} is taken."
|
||||
is_taken: '%{username} is taken.'
|
||||
user_could_not_be_saved: User could not be saved. %{e_message}
|
||||
username_is_reserved: username is reserved
|
||||
user_block:
|
||||
|
|
@ -125,7 +126,7 @@ en:
|
|||
not_enabled: User subscriptions are not enabled for the source.
|
||||
users:
|
||||
deleted_user:
|
||||
name: "[Deleted User]"
|
||||
name: '[Deleted User]'
|
||||
setting:
|
||||
invalid_hex: is not a valid hex color
|
||||
invalid_rss: is not a valid RSS/Atom feed
|
||||
|
|
|
|||
|
|
@ -27,9 +27,9 @@ fr:
|
|||
broadcast:
|
||||
single_active: You can only have one active announcement broadcast
|
||||
comment:
|
||||
deleted: "[deleted]"
|
||||
has_been_deleted: "%{type} has been deleted."
|
||||
hidden: "[hidden by post author]"
|
||||
deleted: '[deleted]'
|
||||
has_been_deleted: '%{type} has been deleted.'
|
||||
hidden: '[hidden by post author]'
|
||||
is_not_valid: is not valid.
|
||||
locked: the discussion is locked on this Post
|
||||
type:
|
||||
|
|
@ -41,7 +41,7 @@ fr:
|
|||
one: You cannot mention more than %{count} users in a comment!
|
||||
other: You cannot mention more than %{count} users in a comment!
|
||||
feedback_message:
|
||||
reported: "(you) previously reported this URL."
|
||||
reported: '(you) previously reported this URL.'
|
||||
github_issue:
|
||||
issue_comment_not_found: Issue comment %{issue_id} not found
|
||||
issue_not_found: Issue %{issue_id} not found
|
||||
|
|
@ -58,7 +58,7 @@ fr:
|
|||
is_not_valid: is not valid.
|
||||
organization:
|
||||
integer_only: Integer only. No sign allowed.
|
||||
reserved_word: "%<value>s is a reserved word. Contact site admins for help registering your organization."
|
||||
reserved_word: '%<value>s is a reserved word. Contact site admins for help registering your organization.'
|
||||
page:
|
||||
body_must_exist: must exist if body_html or body_json doesn't exist.
|
||||
podcast:
|
||||
|
|
@ -110,11 +110,12 @@ fr:
|
|||
unique: can't be an already adjusted tag
|
||||
tweet:
|
||||
tweet_not_found: Tweet not found
|
||||
authentication_error: Authentication error; please contact your Forem admin about possible missing Twitter keys
|
||||
user:
|
||||
could_not_send: confirmation could not be sent. %{e_message}
|
||||
password_not_matched: doesn't match password confirmation
|
||||
has_been_banished: has been banished.
|
||||
is_taken: "%{username} is taken."
|
||||
is_taken: '%{username} is taken.'
|
||||
user_could_not_be_saved: User could not be saved. %{e_message}
|
||||
username_is_reserved: username is reserved
|
||||
user_block:
|
||||
|
|
@ -125,7 +126,7 @@ fr:
|
|||
not_enabled: User subscriptions are not enabled for the source.
|
||||
users:
|
||||
deleted_user:
|
||||
name: "[Deleted User]"
|
||||
name: '[Deleted User]'
|
||||
setting:
|
||||
invalid_hex: is not a valid hex color
|
||||
invalid_rss: is not a valid RSS/Atom feed
|
||||
|
|
|
|||
|
|
@ -316,7 +316,7 @@ RSpec.describe UnifiedEmbed::Registry do
|
|||
end
|
||||
end
|
||||
|
||||
it "returns WikipediaTag for a twitter timeline url" do
|
||||
it "returns WikipediaTag for a wikipedia url" do
|
||||
expect(described_class.find_liquid_tag_for(link: "https://en.wikipedia.org/wiki/Steve_Jobs"))
|
||||
.to eq(WikipediaTag)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -88,6 +88,17 @@ RSpec.describe Tweet, type: :model, vcr: true do
|
|||
tweet = described_class.find_or_fetch(tweet_id)
|
||||
expect(tweet.user_id).to eq(user.id)
|
||||
end
|
||||
|
||||
it "raises an error when Twitter key or secret are missing" do
|
||||
allow(TwitterClient::Client)
|
||||
.to receive(:status)
|
||||
.and_raise(TwitterClient::Errors::BadRequest, "Bad Authentication data.")
|
||||
|
||||
expect do
|
||||
described_class.find_or_fetch(tweet_id)
|
||||
end.to raise_error(TwitterClient::Errors::BadRequest,
|
||||
"Authentication error; please contact your Forem admin about possible missing Twitter keys")
|
||||
end
|
||||
end
|
||||
|
||||
context "when retrieving non existent tweet", vcr: { cassette_name: "twitter_client_status_not_found_extended" } do
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue