Skip to content

Commit 4ea38e5

Browse files
committed
Rescue from OpenSSL::SSL::SSLError (resolves #4)
Adds a new `IndieWeb::Endpoints::SSLError` class that wraps the underlying Ruby standard library SSLError raised by the HTTP gem. _Finally._
1 parent 6aa8c4f commit 4ea38e5

File tree

4 files changed

+15
-0
lines changed

4 files changed

+15
-0
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ From [httprb/http](https://github.com/httprb/http):
8080

8181
- `IndieWeb::Endpoints::HttpError`
8282

83+
From the Ruby Standard Library's [`OpenSSL::SSL::SSLError`](https://ruby-doc.org/stdlib-2.6.9/libdoc/openssl/rdoc/OpenSSL/SSL/SSLError.html):
84+
85+
- `IndieWeb::Endpoints::SSLError`
86+
8387
## Contributing
8488

8589
Interested in helping improve indieweb-endpoints-ruby? Awesome! Your help is greatly appreciated. See [CONTRIBUTING.md](https://github.com/indieweb/indieweb-endpoints-ruby/blob/main/CONTRIBUTING.md) for details.

lib/indieweb/endpoints.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ module Endpoints
1616
class Error < StandardError; end
1717
class HttpError < Error; end
1818
class InvalidURIError < Error; end
19+
class SSLError < Error; end
1920

2021
# Discover a URL's IndieAuth, Micropub, Microsub, and Webmention endpoints
2122
#

lib/indieweb/endpoints/client.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ def response
4343
.get(uri)
4444
rescue HTTP::Error => e
4545
raise HttpError, e
46+
rescue OpenSSL::SSL::SSLError => e
47+
raise SSLError, e
4648
end
4749

4850
private

spec/lib/indieweb/endpoints/client_response_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,12 @@
1212
expect { response }.to raise_error(IndieWeb::Endpoints::HttpError)
1313
end
1414
end
15+
16+
context 'when rescuing from an OpenSSL::SSL::SSLError' do
17+
it 'raises an IndieWeb::Endpoints::SSLError' do
18+
stub_request(:get, url).to_raise(OpenSSL::SSL::SSLError)
19+
20+
expect { response }.to raise_error(IndieWeb::Endpoints::SSLError)
21+
end
22+
end
1523
end

0 commit comments

Comments
 (0)