Sha256: da8e1b938f9cac70021f3b7deb7c066e836d4705447081c840e0534b488923a9
Contents?: true
Size: 901 Bytes
Versions: 6
Compression:
Stored size: 901 Bytes
Contents
require 'faraday' # @private module Faraday # @private class Response::RaiseHttp4xx < Response::Middleware def self.register_on_complete(env) env[:response].on_complete do |response| case response[:status].to_i when 400 raise Instagram::BadRequest, error_message(response) when 404 raise Instagram::NotFound, error_message(response) end end end def initialize(app) super @parser = nil end private def self.error_message(response) "#{response[:method].to_s.upcase} #{response[:url].to_s}: #{response[:status]}#{error_body(response[:body])}" end def self.error_body(body) if body.nil? nil elsif body['meta'] and body['meta']['error_message'] and not body['meta']['error_message'].empty? ": #{body['meta']['error_message']}" end end end end
Version data entries
6 entries across 6 versions & 3 rubygems