Sha256: 714b07fac900f59a6bf33090fc1e9b9147942520386804003986a25be9f8ba93

Contents?: true

Size: 585 Bytes

Versions: 2

Compression:

Stored size: 585 Bytes

Contents

require 'faraday'
require 'uatu/error'

module Uatu
  module Response
    
    class RaiseMarvelError < Faraday::Response::Middleware

      def on_complete(env)
        status  = env[:status]
        body    = env[:body]
        headers = env[:response_headers]

        parsed_body = JSON.parse(body)
        code    = parsed_body['code']
        message = parsed_body['message'] || parsed_body['status']

        unless code.to_i == 200
          raise Uatu::Error::ClientError.new "#{code} - #{message}\n ", {body: body, headers: headers}
        end

      end

    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
uatu-marvel-0.0.1.1 lib/uatu/response.rb
uatu-marvel-0.0.1 lib/uatu/response.rb