diff --git a/changelog.md b/changelog.md index c1129828..8a22e015 100644 --- a/changelog.md +++ b/changelog.md @@ -7,6 +7,8 @@ New features: Updated features: + * Add fbtrace_id, x-fb-rev, x-fb-debug to error messages and error class ([#668](https://github.com/arsduo/koala/pull/686)) + Removed features: Internal improvements: diff --git a/lib/koala/errors.rb b/lib/koala/errors.rb index 4b48fc5d..a5b5a673 100644 --- a/lib/koala/errors.rb +++ b/lib/koala/errors.rb @@ -22,6 +22,7 @@ class APIError < ::Koala::KoalaError :fb_error_user_msg, :fb_error_user_title, :fb_error_trace_id, + :fb_error_debug_trace_id, :fb_error_debug, :fb_error_rev, :fb_buc_usage, @@ -65,8 +66,9 @@ def initialize(http_status, response_body, error_info = nil) self.fb_error_message = error_info["message"] self.fb_error_user_msg = error_info["error_user_msg"] self.fb_error_user_title = error_info["error_user_title"] + self.fb_error_trace_id = error_info["fbtrace_id"] - self.fb_error_trace_id = error_info["x-fb-trace-id"] + self.fb_error_debug_trace_id = error_info["x-fb-trace-id"] self.fb_error_debug = error_info["x-fb-debug"] self.fb_error_rev = error_info["x-fb-rev"] self.fb_buc_usage = json_parse_for(error_info, "x-business-use-case-usage") @@ -74,7 +76,7 @@ def initialize(http_status, response_body, error_info = nil) self.fb_app_usage = json_parse_for(error_info, "x-app-usage") error_array = [] - %w(type code error_subcode message error_user_title error_user_msg x-fb-trace-id).each do |key| + %w(type code error_subcode message error_user_title error_user_msg fbtrace_id x-fb-trace-id x-fb-debug x-fb-rev).each do |key| error_array << "#{key}: #{error_info[key]}" if error_info[key] end diff --git a/spec/cases/error_spec.rb b/spec/cases/error_spec.rb index b19cccd2..07bce941 100644 --- a/spec/cases/error_spec.rb +++ b/spec/cases/error_spec.rb @@ -34,7 +34,8 @@ 'error_subcode' => 'subcode', 'error_user_msg' => 'error user message', 'error_user_title' => 'error user title', - 'x-fb-trace-id' => 'fb trace id', + 'fbtrace_id' => 'fb trace id', + 'x-fb-trace-id' => 'x-fb trace id', 'x-fb-debug' => 'fb debug token', 'x-fb-rev' => 'fb revision', 'x-business-use-case-usage' => BUC_USAGE_JSON, @@ -52,6 +53,7 @@ :fb_error_user_msg => 'error user message', :fb_error_user_title => 'error user title', :fb_error_trace_id => 'fb trace id', + :fb_error_debug_trace_id => 'x-fb trace id', :fb_error_debug => 'fb debug token', :fb_error_rev => 'fb revision', :fb_buc_usage => JSON.parse(BUC_USAGE_JSON), @@ -64,7 +66,7 @@ end it "sets the error message appropriately" do - expect(error.message).to eq("type: type, code: 1, error_subcode: subcode, message: message, error_user_title: error user title, error_user_msg: error user message, x-fb-trace-id: fb trace id [HTTP 400]") + expect(error.message).to eq("type: type, code: 1, error_subcode: subcode, message: message, error_user_title: error user title, error_user_msg: error user message, fbtrace_id: fb trace id, x-fb-trace-id: x-fb trace id, x-fb-debug: fb debug token, x-fb-rev: fb revision [HTTP 400]") end end diff --git a/spec/cases/graph_error_checker_spec.rb b/spec/cases/graph_error_checker_spec.rb index 6245d433..204a47a1 100644 --- a/spec/cases/graph_error_checker_spec.rb +++ b/spec/cases/graph_error_checker_spec.rb @@ -76,10 +76,12 @@ module Facebook "error_subcode" => "FB error subcode", "message" => "An error occurred!", "error_user_msg" => "A user msg", - "error_user_title" => "usr title" + "error_user_title" => "usr title", + "fbtrace_id" => "fbtrace_id" } body.replace({"error" => error_data}.to_json) + expect(error.fb_error_trace_id).to eq(error_data["fbtrace_id"]) expect(error.fb_error_type).to eq(error_data["type"]) expect(error.fb_error_code).to eq(error_data["code"]) expect(error.fb_error_subcode).to eq(error_data["error_subcode"]) @@ -97,7 +99,7 @@ module Facebook "x-ad-account-usage" => { 'c' => 3, 'd' => 4 }.to_json, "x-app-usage" => { 'e' => 5, 'f' => 6 }.to_json ) - expect(error.fb_error_trace_id).to eq(headers["x-fb-trace-id"]) + expect(error.fb_error_debug_trace_id).to eq(headers["x-fb-trace-id"]) expect(error.fb_error_debug).to eq(headers["x-fb-debug"]) expect(error.fb_error_rev).to eq(headers["x-fb-rev"]) expect(error.fb_buc_usage).to eq({ 'a' => 1, 'b' => 2 })