lib/auth0/mixins/httpproxy.rb in auth0-4.7.0 vs lib/auth0/mixins/httpproxy.rb in auth0-4.8.0
- old
+ new
@@ -4,11 +4,11 @@
# for now, if you want to feel free to use your own http client
module HTTPProxy
attr_accessor :headers, :base_uri, :timeout
# proxying requests from instance methods to HTTP class methods
- %i(get post post_file put patch delete).each do |method|
+ %i(get post post_file put patch delete delete_with_body).each do |method|
define_method(method) do |path, body = {}, extra_headers = {}|
safe_path = URI.escape(path)
body = body.delete_if { |_, v| v.nil? }
result = if method == :get
# Mutate the headers property to add parameters.
@@ -18,23 +18,26 @@
get_headers = headers.merge extra_headers
# Make the call with extra_headers, if provided.
call(:get, url(safe_path), timeout, get_headers)
elsif method == :delete
call(:delete, url(safe_path), timeout, add_headers({params: body}))
+ elsif method == :delete_with_body
+ call(:delete, url(safe_path), timeout, headers, body)
elsif method == :post_file
body.merge!(multipart: true)
call(:post, url(safe_path), timeout, headers, body)
else
call(method, url(safe_path), timeout, headers, body.to_json)
end
case result.code
when 200...226 then safe_parse_json(result.body)
- when 400 then raise Auth0::BadRequest, result.to_s
- when 401 then raise Auth0::Unauthorized, result.body
- when 403 then raise Auth0::AccessDenied, result.body
- when 404 then raise Auth0::NotFound, result.body
- when 500 then raise Auth0::ServerError, result.body
- else raise Auth0::Unsupported, result.body
+ when 400 then raise Auth0::BadRequest.new(result.body, code: result.code, headers: result.headers)
+ when 401 then raise Auth0::Unauthorized.new(result.body, code: result.code, headers: result.headers)
+ when 403 then raise Auth0::AccessDenied.new(result.body, code: result.code, headers: result.headers)
+ when 404 then raise Auth0::NotFound.new(result.body, code: result.code, headers: result.headers)
+ when 429 then raise Auth0::RateLimitEncountered.new(result.body, code: result.code, headers: result.headers)
+ when 500 then raise Auth0::ServerError.new(result.body, code: result.code, headers: result.headers)
+ else raise Auth0::Unsupported.new(result.body, code: result.code, headers: result.headers)
end
end
end
def url(path)