Skip to content

Commit

Permalink
Recover from errors raised when normalizing an URL.
Browse files Browse the repository at this point in the history
Some URLs can be parsed but when trying to normalize them raise an error, it seems. This should remove some production errors (the problematic URL will be replaced with a blank string).
  • Loading branch information
amatriain committed Sep 4, 2017
1 parent b2ec9d2 commit 1f1ddc1
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/url_normalizer.rb
Expand Up @@ -98,7 +98,13 @@ def self.normalize_entry_url(url, entry)
end
end

normalized_url = Addressable::URI.parse(normalized_url).normalize.to_s
begin
normalized_url = Addressable::URI.parse(normalized_url).normalize.to_s
rescue Addressable::URI::InvalidURIError => e
Rails.logger.warn "URL #{normalized_url} cannot be normalized, removing it"
normalized_url = ''
end

return normalized_url
end

Expand Down

0 comments on commit 1f1ddc1

Please sign in to comment.