Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Catches 502 and 504 errors. #70

Merged
merged 1 commit into from

3 participants

@philnash

On occasion I have experienced Faraday::Error::ParsingError errors from the
gem because they are not caught in the HTTP Exception middleware. They then
fall through to the JSON parser, but since it is returning HTML from nginx
the parser throws an error instead.

I have added the extra errors and tests that include the HTML returned to
ensure that the middleware catches the errors before the JSON parser sees
them.

@philnash philnash Catches 502 and 504 errors.
On occasion I have experienced Faraday::Error::ParsingError errors from the
gem because they are not caught in the HTTP Exception middleware. They then
fall through to the JSON parser, but since it is returning HTML from nginx
the parser throws an error instead.

I have added the extra errors and tests that include the HTML returned to
ensure that the middleware catches the errors before the JSON parser sees
them.
b48cf92
@philnash

Should fix #43 and #44

@heatonjb heatonjb merged commit b48cf92 into from
@heatonjb
Owner
@heatonjb
Owner
@philnash

Done. Might be worth updating the README or adding a CONTRIBUTING file with this information in, so that contributors know about this up front.

Thanks

@heatonjb
Owner
@heatonjb
Owner
@philnash

Hey Jon,

We are certainly working with Instagram fairly regularly, it would definitely be worth a chat. Can you drop me an email on phil@mintdigital.com and we'll sort something out?

Phil

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 3, 2013
  1. @philnash

    Catches 502 and 504 errors.

    philnash authored
    On occasion I have experienced Faraday::Error::ParsingError errors from the
    gem because they are not caught in the HTTP Exception middleware. They then
    fall through to the JSON parser, but since it is returning HTML from nginx
    the parser throws an error instead.
    
    I have added the extra errors and tests that include the HTML returned to
    ensure that the middleware catches the errors before the JSON parser sees
    them.
This page is out of date. Refresh to see the latest.
View
4 lib/faraday/raise_http_exception.rb
@@ -13,8 +13,12 @@ def call(env)
raise Instagram::NotFound, error_message_400(response)
when 500
raise Instagram::InternalServerError, error_message_500(response, "Something is technically wrong.")
+ when 502
+ raise Instagram::BadGateway, error_message_500(response, "The server returned an invalid or incomplete response.")
when 503
raise Instagram::ServiceUnavailable, error_message_500(response, "Instagram is rate limiting your requests.")
+ when 504
+ raise Instagram::GatewayTimeout, error_message_500(response, "504 Gateway Time-out")
end
end
end
View
6 lib/instagram/error.rb
@@ -11,9 +11,15 @@ class NotFound < Error; end
# Raised when Instagram returns the HTTP status code 500
class InternalServerError < Error; end
+ # Raised when Instagram returns the HTTP status code 502
+ class BadGateway < Error; end
+
# Raised when Instagram returns the HTTP status code 503
class ServiceUnavailable < Error; end
+ # Raised when Instagram returns the HTTP status code 504
+ class GatewayTimeout < Error; end
+
# Raised when a subscription payload hash is invalid
class InvalidSignature < Error; end
end
View
30 spec/faraday/response_spec.rb
@@ -39,4 +39,34 @@
end.to raise_error(Instagram::BadRequest, /Bad words are bad./)
end
end
+
+ context 'when a 502 is raised with an HTML response' do
+ before do
+ stub_get('users/self/feed.json').to_return(
+ :body => '<html><body><h1>502 Bad Gateway</h1> The server returned an invalid or incomplete response. </body></html>',
+ :status => 502
+ )
+ end
+
+ it 'should raise an Instagram::BadGateway' do
+ lambda do
+ @client.user_media_feed()
+ end.should raise_error(Instagram::BadGateway)
+ end
+ end
+
+ context 'when a 504 is raised with an HTML response' do
+ before do
+ stub_get('users/self/feed.json').to_return(
+ :body => '<html> <head><title>504 Gateway Time-out</title></head> <body bgcolor="white"> <center><h1>504 Gateway Time-out</h1></center> <hr><center>nginx</center> </body> </html>',
+ :status => 504
+ )
+ end
+
+ it 'should raise an Instagram::GatewayTimeout' do
+ lambda do
+ @client.user_media_feed()
+ end.should raise_error(Instagram::GatewayTimeout)
+ end
+ end
end
Something went wrong with that request. Please try again.