mirror of
https://github.com/lostisland/faraday.git
synced 2025-10-08 00:03:41 -04:00
adds Faraday::Response::RaiseError for HTTP 408 when using raise error middleware
This commit is contained in:
parent
2824eaf968
commit
b47e22bf5d
@ -112,6 +112,10 @@ module Faraday
|
||||
class ProxyAuthError < ClientError
|
||||
end
|
||||
|
||||
# Raised by Faraday::Response::RaiseError in case of a 408 response.
|
||||
class RequestTimeoutError < ClientError
|
||||
end
|
||||
|
||||
# Raised by Faraday::Response::RaiseError in case of a 409 response.
|
||||
class ConflictError < ClientError
|
||||
end
|
||||
|
@ -24,6 +24,8 @@ module Faraday
|
||||
# mimic the behavior that we get with proxy requests with HTTPS
|
||||
msg = %(407 "Proxy Authentication Required")
|
||||
raise Faraday::ProxyAuthError.new(msg, response_values(env))
|
||||
when 408
|
||||
raise Faraday::RequestTimeoutError, response_values(env)
|
||||
when 409
|
||||
raise Faraday::ConflictError, response_values(env)
|
||||
when 422
|
||||
|
@ -11,6 +11,7 @@ RSpec.describe Faraday::Response::RaiseError do
|
||||
stub.get('forbidden') { [403, { 'X-Reason' => 'because' }, 'keep looking'] }
|
||||
stub.get('not-found') { [404, { 'X-Reason' => 'because' }, 'keep looking'] }
|
||||
stub.get('proxy-error') { [407, { 'X-Reason' => 'because' }, 'keep looking'] }
|
||||
stub.get('request-timeout') { [408, { 'X-Reason' => 'because' }, 'keep looking'] }
|
||||
stub.get('conflict') { [409, { 'X-Reason' => 'because' }, 'keep looking'] }
|
||||
stub.get('unprocessable-entity') { [422, { 'X-Reason' => 'because' }, 'keep looking'] }
|
||||
stub.get('4xx') { [499, { 'X-Reason' => 'because' }, 'keep looking'] }
|
||||
@ -79,6 +80,17 @@ RSpec.describe Faraday::Response::RaiseError do
|
||||
end
|
||||
end
|
||||
|
||||
it 'raises Faraday::RequestTimeoutError for 408 responses' do
|
||||
expect { conn.get('request-timeout') }.to raise_error(Faraday::RequestTimeoutError) do |ex|
|
||||
expect(ex.message).to eq('the server responded with status 408')
|
||||
expect(ex.response[:headers]['X-Reason']).to eq('because')
|
||||
expect(ex.response[:status]).to eq(408)
|
||||
expect(ex.response_status).to eq(408)
|
||||
expect(ex.response_body).to eq('keep looking')
|
||||
expect(ex.response_headers['X-Reason']).to eq('because')
|
||||
end
|
||||
end
|
||||
|
||||
it 'raises Faraday::ConflictError for 409 responses' do
|
||||
expect { conn.get('conflict') }.to raise_error(Faraday::ConflictError) do |ex|
|
||||
expect(ex.message).to eq('the server responded with status 409')
|
||||
|
Loading…
x
Reference in New Issue
Block a user