Skip to content

Commit

Permalink
Merge pull request #119 from keboola/kacurez-cannot-include-retry-ST-…
Browse files Browse the repository at this point in the history
…1570

retry on "cannnot include" error
  • Loading branch information
kacurez authored May 28, 2024
2 parents dd98a44 + 28e9aeb commit 572b8e0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/keboola/facebook/api/request.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion test/keboola/facebook/api/request_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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"]})

Expand Down Expand Up @@ -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)))
Expand Down

0 comments on commit 572b8e0

Please sign in to comment.