Sha256: 6e7cf5ad9428a67b998bc1887afb44da87e552203a86e040cac77208bb9e6d8e
Contents?: true
Size: 898 Bytes
Versions: 2
Compression:
Stored size: 898 Bytes
Contents
require 'faraday' require 'twitter/error' module Twitter module REST module Response class RaiseError < Faraday::Response::Middleware def on_complete(response) status_code = response.status.to_i klass = Twitter::Error.errors[status_code] return unless klass raise(handle_forbidden_errors(response)) if klass == Twitter::Error::Forbidden raise(klass.from_response(response)) end private def handle_forbidden_errors(response) error = Twitter::Error::Forbidden.from_response(response) klass = Twitter::Error.forbidden_messages[error.message] if klass klass.from_response(response) else error end end end end end end Faraday::Response.register_middleware twitter_raise_error: Twitter::REST::Response::RaiseError
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
twitter-6.1.0 | lib/twitter/rest/response/raise_error.rb |
twitter-6.0.0 | lib/twitter/rest/response/raise_error.rb |