mirror of
https://github.com/lostisland/faraday.git
synced 2025-10-06 00:03:36 -04:00
Merge branch 'master' of https://github.com/lostisland/faraday into faraday-website
This commit is contained in:
commit
06b4fac02b
@ -61,6 +61,10 @@ module Faraday
|
||||
class ProxyAuthError < ClientError
|
||||
end
|
||||
|
||||
# Raised by Faraday::Response::RaiseError in case of a 409 response.
|
||||
class ConflictError < ClientError
|
||||
end
|
||||
|
||||
# Raised by Faraday::Response::RaiseError in case of a 422 response.
|
||||
class UnprocessableEntityError < 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 409
|
||||
raise Faraday::ConflictError, response_values(env)
|
||||
when 422
|
||||
raise Faraday::UnprocessableEntityError, response_values(env)
|
||||
when ClientErrorStatuses
|
||||
|
@ -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('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'] }
|
||||
stub.get('server-error') { [500, { 'X-Error' => 'bailout' }, 'fail'] }
|
||||
@ -57,6 +58,13 @@ RSpec.describe Faraday::Response::RaiseError do
|
||||
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')
|
||||
expect(ex.response[:headers]['X-Reason']).to eq('because')
|
||||
end
|
||||
end
|
||||
|
||||
it 'raises Faraday::UnprocessableEntityError for 422 responses' do
|
||||
expect { conn.get('unprocessable-entity') }.to raise_error(Faraday::UnprocessableEntityError) do |ex|
|
||||
expect(ex.message).to eq('the server responded with status 422')
|
||||
|
Loading…
x
Reference in New Issue
Block a user