Module: Vend::HttpErrors
- Included in:
- Middleware::HttpException
- Defined in:
- lib/vend/exception.rb
Constant Summary collapse
- ERRORS =
{ 400 => Vend::BadRequest, 401 => Vend::Unauthorized, 403 => Vend::Forbidden, 404 => Vend::NotFound, 405 => Vend::MethodNotAllowed, 406 => Vend::NotAccepted, 408 => Vend::TimeOut, 409 => Vend::ResourceConflict, 429 => Vend::TooManyRequests, 500 => Vend::InternalServerError, 502 => Vend::BadGateway, 503 => Vend::ServiceUnavailable, 504 => Vend::GatewayTimeout, 509 => Vend::BandwidthLimitExceeded }.freeze
Instance Method Summary collapse
Instance Method Details
#throw_http_exception!(code, env) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/vend/exception.rb', line 42 def throw_http_exception!(code, env) return unless ERRORS.keys.include? code response_headers = {} unless env.body.empty? response_headers = begin Oj.load(env.body, symbol_keys: true) rescue {} end end unless env[:response_headers] && env[:response_headers]['X-Retry-After'].nil? response_headers[:retry_after] = env[:response_headers]['X-Retry-After'].to_i end raise ERRORS[code].new(response_headers), env.body end |