Sha256: 01f624e136f8d2c2753e8b052e22b820195e78e71c1235526e7fe92bdd3515e9
Contents?: true
Size: 967 Bytes
Versions: 4
Compression:
Stored size: 967 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] if klass error = if klass == Twitter::Error::Forbidden handle_forbidden_errors(response) else klass.from_response(response) end fail(error) end 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 :raise_error => Twitter::REST::Response::RaiseError
Version data entries
4 entries across 4 versions & 1 rubygems