mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
Remove use of rescue nil.
* `rescue nil` is a really bad pattern to use in our code base. We should rescue errors that we expect the code to throw and not rescue everything because we're unsure of what errors the code would throw. This would reduce the amount of pain we face when debugging why something isn't working as expexted. I've been bitten countless of times by errors being swallowed as a result during debugging sessions.
This commit is contained in:
@@ -12,7 +12,10 @@ class EmbeddableHost < ActiveRecord::Base
|
||||
def self.record_for_url(uri)
|
||||
|
||||
if uri.is_a?(String)
|
||||
uri = URI(UrlHelper.escape_uri(uri)) rescue nil
|
||||
uri = begin
|
||||
URI(UrlHelper.escape_uri(uri))
|
||||
rescue URI::InvalidURIError
|
||||
end
|
||||
end
|
||||
return false unless uri.present?
|
||||
|
||||
@@ -40,7 +43,11 @@ class EmbeddableHost < ActiveRecord::Base
|
||||
# Work around IFRAME reload on WebKit where the referer will be set to the Forum URL
|
||||
return true if url&.starts_with?(Discourse.base_url)
|
||||
|
||||
uri = URI(UrlHelper.escape_uri(url)) rescue nil
|
||||
uri = begin
|
||||
URI(UrlHelper.escape_uri(url))
|
||||
rescue URI::InvalidURIError
|
||||
end
|
||||
|
||||
uri.present? && record_for_url(uri).present?
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user