Sha256: 3fe18f38601afa89f79f408e639321ab68437132204eaa6d23e1108b3eb0a3b4
Contents?: true
Size: 976 Bytes
Versions: 9
Compression:
Stored size: 976 Bytes
Contents
module JsonApiClient module Middleware class Status < Faraday::Middleware def call(environment) @app.call(environment).on_complete do |env| handle_status(env[:status], env) # look for meta[:status] if env[:body].is_a?(Hash) code = env[:body].fetch("meta", {}).fetch("status", 200).to_i handle_status(code, env) end end rescue Faraday::ConnectionFailed, Faraday::TimeoutError raise Errors::ConnectionError, environment end protected def handle_status(code, env) case code when 200..399 when 403 raise Errors::AccessDenied, env when 404 raise Errors::NotFound, env[:url] when 400..499 # some other error when 500..599 raise Errors::ServerError, env else raise Errors::UnexpectedStatus.new(code, env[:url]) end end end end end
Version data entries
9 entries across 9 versions & 1 rubygems