From 8ff2759f5ff91e629d9d4717a11f9cc3c27e2ec5 Mon Sep 17 00:00:00 2001 From: Tarek Khalil Date: Wed, 11 Oct 2017 16:29:17 +0100 Subject: [PATCH] Do NOT check for OAuthException code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I encountered a situation where I receive a Facebook error with code `100` and type `OAuthException`. I don’t think we need to check for codes to decide if it is an `AuthenticationError` or `ClientError`. --- lib/koala/api/graph_error_checker.rb | 9 +-------- spec/cases/graph_error_checker_spec.rb | 11 ----------- 2 files changed, 1 insertion(+), 19 deletions(-) diff --git a/lib/koala/api/graph_error_checker.rb b/lib/koala/api/graph_error_checker.rb index 44f0328e..7852e345 100644 --- a/lib/koala/api/graph_error_checker.rb +++ b/lib/koala/api/graph_error_checker.rb @@ -11,10 +11,6 @@ def initialize(http_status, body, headers) @headers = headers end - # Facebook has a set of standardized error codes, some of which represent problems with the - # token. - AUTHENTICATION_ERROR_CODES = [102, 190, 450, 452, 2500] - # Facebook can return debug information in the response headers -- see # https://developers.facebook.com/docs/graph-api/using-graph-api#bugdebug DEBUG_HEADERS = ["x-fb-debug", "x-fb-rev", "x-fb-trace-id"] @@ -38,10 +34,7 @@ def error_class end def auth_error? - # tbh, I'm not sure why we restrict Facebook-reported OAuthExceptions to only those without - # codes or whose codes match the list above -- let's investigate changing this later. - error_info['type'] == 'OAuthException' && - (!error_info['code'] || AUTHENTICATION_ERROR_CODES.include?(error_info['code'].to_i)) + error_info['type'] == 'OAuthException' end def error_info diff --git a/spec/cases/graph_error_checker_spec.rb b/spec/cases/graph_error_checker_spec.rb index d57ef6e7..b8c55ba2 100644 --- a/spec/cases/graph_error_checker_spec.rb +++ b/spec/cases/graph_error_checker_spec.rb @@ -3,10 +3,6 @@ module Koala module Facebook RSpec.describe GraphErrorChecker do - it "defines a set of AUTHENTICATION_ERROR_CODES" do - expect(GraphErrorChecker::AUTHENTICATION_ERROR_CODES).to match_array([102, 190, 450, 452, 2500]) - end - it "defines a set of DEBUG_HEADERS" do expect(GraphErrorChecker::DEBUG_HEADERS).to match_array([ "x-fb-rev", @@ -95,13 +91,6 @@ module Facebook body.replace({"error" => {"type" => "OAuthException"}}.to_json) expect(error).to be_an(AuthenticationError) end - - GraphErrorChecker::AUTHENTICATION_ERROR_CODES.each do |error_code| - it "if FB says it's an OAuthException and it has code #{error_code}" do - body.replace({"error" => {"type" => "OAuthException", "code" => error_code}}.to_json) - expect(error).to be_an(AuthenticationError) - end - end end # Note: I'm not sure why this behavior was implemented, it may be incorrect. To