Class: Remind101::Middleware::RaiseError

Inherits:
Faraday::Response::Middleware
  • Object
show all
Defined in:
lib/remind101/middleware/raise_error.rb

Constant Summary collapse

ClientErrorStatuses =
401...600

Instance Method Summary collapse

Instance Method Details

#on_complete(env) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/remind101/middleware/raise_error.rb', line 6

def on_complete(env)
  case env[:status]
  when 400
    raise Remind101::Error::BadInput, response_values(env)
  when 401
    raise Remind101::Error::Unauthorized, response_values(env)
  when 404
    raise Remind101::Error::ResourceNotFound, response_values(env)
  when 422
    raise Remind101::Error::ValidationError, response_values(env)
  when 407
    # mimic the behavior that we get with proxy requests with HTTPS
    raise Remind101::Error::ConnectionFailed, %{407 "Proxy Authentication Required "}
  when ClientErrorStatuses
    raise Remind101::Error::ClientError, response_values(env)
  end
end

#response_values(env) ⇒ Object



24
25
26
# File 'lib/remind101/middleware/raise_error.rb', line 24

def response_values(env)
  Hashie::Mash.new status: env[:status], headers: env[:response_headers], body: env[:body]
end