I sort of solved my issue:
def unshorten(uri)
begin
response = HTTParty.get(uri, limit: 50)
rescue URI::InvalidURIError => error
bad_uri = error.message.match(/^bad\sURI\(is\snot\sURI\?\)\:\s(.*)$/)[1]
good_uri = URI.encode bad_uri
response = self.unshorten good_uri
end
response
end
I don't feel particularly comfortable fetching the URI from the error message string but it seems there's no other way. Or is there? :)