From 28e9aeb29f6ccfa925e6e3006ed7e0fe3c2c13df Mon Sep 17 00:00:00 2001 From: kacurez Date: Tue, 28 May 2024 16:52:39 +0200 Subject: [PATCH] retry on "cannnot include" error --- src/keboola/facebook/api/request.clj | 5 +++-- test/keboola/facebook/api/request_test.clj | 6 +++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/keboola/facebook/api/request.clj b/src/keboola/facebook/api/request.clj index b652ac9..9abab6c 100644 --- a/src/keboola/facebook/api/request.clj +++ b/src/keboola/facebook/api/request.clj @@ -64,7 +64,8 @@ (re-find #"Please reduce the amount of data" (:body e)))) (and (<= 400 status 600) (re-find #"since param is not valid. Metrics data is available for the last 2 years" (:body e))) - (re-find #"This method must be called with a Page Access Token" (:body e))))) + (re-find #"This method must be called with a Page Access Token" (:body e)) + (re-find #"\(#100\) Cannot include" (:body e))))) (def MIN_TRY_LIMIT_COUNT 3) (def MIN_TRY_LIMIT 1) @@ -77,7 +78,7 @@ (log-error "Recoverable error encountered: Media Posted Before Business Account Conversion Error" (:body e)) empty-response) (catch retry-exception? e - (Thread/sleep 1000) + (Thread/sleep 60000) (if (zero? min-limit-count) (throw+ e) (let [current-limit (or (parse-limit-from-url url) DEFAULT_LIMIT) diff --git a/test/keboola/facebook/api/request_test.clj b/test/keboola/facebook/api/request_test.clj index 36092c5..0ea239e 100644 --- a/test/keboola/facebook/api/request_test.clj +++ b/test/keboola/facebook/api/request_test.clj @@ -27,6 +27,10 @@ (def error-400-response {:request-time 21463, :repeatable? false, :protocol-version {:name "HTTP", :major 1, :minor 1}, :streaming? true, :chunked? false, :reason-phrase "Internal Server Error", :headers {}, :orig-content-encoding nil, :status 400, :length 108, :body "{\"error\":{\"code\":1,\"message\":\"There cannot be more than 93 days (8035200 s) between since and until\"}}"}) +(def cannot-include-error + {:request-time 21463, :repeatable? false, :protocol-version {:name "HTTP", :major 1, :minor 1}, :streaming? true, :chunked? false, :reason-phrase "Internal Server Error", :headers {}, :orig-content-encoding nil, :status 400, :length 108, :body "{\"error\":{\"code\":1,\"message\":\"(#100) Cannot include account_id, account_name, ad_id, ad_name, adset_id, adset_name, campaign_id, campaign_name, impressions, clicks, spend, reach in summary param because they weren't there while creating the report run. All available values are:\"}}"}) + + (def unknown-error-response {:request-time 30136, :repeatable? false, :protocol-version {:name "HTTP", :major 1, :minor 1}, :streaming? true, :chunked? false, :reason-phrase "Internal Server Error", :headers {}, :orig-content-encoding nil, :status 500, :length 77, :body "{\"error\":{\"code\":1,\"message\":\"An unknown error occurred\",\"error_subcode\":99}}", :trace-redirects ["https://graph.facebook.com/v2.8/adsblablabla"]}) @@ -65,7 +69,7 @@ success-response (do (dec-error-count) - (rand-nth [unexpected-error-response unknown-error-response reduce-data-response something-went-wrong-error-response]))))}) + (rand-nth [unexpected-error-response unknown-error-response reduce-data-response something-went-wrong-error-response cannot-include-error]))))}) (deftest test-retry-on-html-error (is (sut/retry-exception? something-went-wrong-error-response)))