Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rescue common errors and raise LinkThumbnailer error? #71

Closed
maia opened this issue Aug 21, 2015 · 2 comments
Closed

rescue common errors and raise LinkThumbnailer error? #71

maia opened this issue Aug 21, 2015 · 2 comments

Comments

@maia
Copy link
Contributor

maia commented Aug 21, 2015

When using LinkThumbnailer, quite a lot of errors need to be accounted for (that aren't caused by LinkThumbnailer itself but e.g. Errno, Net, OpenSSL, SocketError, URI,…). Would it be helpful to rescue all these errors in LinkThumbnailer and raise a single LinkThumbnailer::HttpError error that then can easily be rescued? That would prevent everyone using LinkThumbnailer from manually adding errors to a long list.

EXCEPTIONS  = [Errno::ECONNREFUSED, Errno::ECONNRESET, Errno::EHOSTUNREACH, Errno::EINVAL,
                Errno::ENETUNREACH, Errno::ETIMEDOUT, LinkThumbnailer::BadUriFormat,
                LinkThumbnailer::FormatNotSupported, LinkThumbnailer::RedirectLimit,
                Net::HTTP::Persistent::Error, Net::HTTPError, Net::HTTPFatalError,
                Net::HTTPInternalServerError, Net::HTTPMethodNotAllowed, Net::HTTPServerException,
                Net::HTTPServiceUnavailable, Net::OpenTimeout, Net::ReadTimeout,
                OpenSSL::SSL::SSLError, SocketError, Timeout::Error, URI::InvalidURIError,
                URI::BadURIError, ArgumentError].freeze
@maia
Copy link
Contributor Author

maia commented Aug 21, 2015

Here's another one to catch:

> LinkThumbnailer.generate("http://www.mandelbaum.at/books/806/7636")
Nokogiri::XML::SyntaxError: Unsupported encoding ISO-8895-15
File "/app/vendor/bundle/ruby/2.2.0/gems/nokogiri-1.6.6.2/lib/nokogiri/xml/document.rb" line 55 in read_memory
File "/app/vendor/bundle/ruby/2.2.0/gems/nokogiri-1.6.6.2/lib/nokogiri/xml/document.rb" line 55 in parse
File "/app/vendor/bundle/ruby/2.2.0/gems/nokogiri-1.6.6.2/lib/nokogiri/xml.rb" line 34 in XML
File "/app/vendor/bundle/ruby/2.2.0/gems/nokogiri-1.6.6.2/lib/nokogiri/html/document.rb" line 256 in detect_encoding
File "/app/vendor/bundle/ruby/2.2.0/gems/nokogiri-1.6.6.2/lib/nokogiri/html/document.rb" line 201 in parse
File "/app/vendor/bundle/ruby/2.2.0/gems/nokogiri-1.6.6.2/lib/nokogiri/html.rb" line 15 in HTML
File "/app/vendor/bundle/ruby/2.2.0/gems/link_thumbnailer-3.0.2/lib/link_thumbnailer/parser.rb" line 9 in call
File "/app/vendor/bundle/ruby/2.2.0/gems/link_thumbnailer-3.0.2/lib/link_thumbnailer/scraper.rb" line 27 in initialize
File "/app/vendor/bundle/ruby/2.2.0/gems/link_thumbnailer-3.0.2/lib/link_thumbnailer/page.rb" line 36 in new
File "/app/vendor/bundle/ruby/2.2.0/gems/link_thumbnailer-3.0.2/lib/link_thumbnailer/page.rb" line 36 in scraper
File "/app/vendor/bundle/ruby/2.2.0/gems/link_thumbnailer-3.0.2/lib/link_thumbnailer/page.rb" line 18 in generate
File "/app/vendor/bundle/ruby/2.2.0/gems/link_thumbnailer-3.0.2/lib/link_thumbnailer.rb" line 16 in generate

@gottfrois
Copy link
Owner

I've handled http errors and nokogiri error. You can use LinkThumbnailer::Exceptions to rescue all link_thumbnailer's exceptions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants