Skip to content

Commit 907b61b

Browse files
fix(SUPPORT-14907): log errors when page token lookup fails
Previously, exceptions during page token lookup were silently swallowed, causing the component to fall back to user token without any indication of what went wrong. This led to confusing 403 Forbidden errors when the user token lacked permissions for page insights. Changes: - Replace swallow-exceptions macro with try-with-warning that logs errors - Add detailed error message when both /me/accounts and page details fail - Only attempt page details API if accounts list lookup didn't find token - Improve logging to help diagnose token permission issues Co-Authored-By: Zora Jelínková <zora.jelinkova@keboola.com>
1 parent d6f7cc3 commit 907b61b

1 file changed

Lines changed: 20 additions & 8 deletions

File tree

src/keboola/facebook/extractor/query.clj

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,29 @@
2323
all-rows (apply concat nested-data)]
2424
(output/write-rows all-rows out-dir prefix false (incremental? query))))
2525

26-
(defmacro swallow-exceptions [& body]
27-
`(try ~@body (catch Exception e#)))
26+
(defmacro try-with-warning [context & body]
27+
`(try ~@body
28+
(catch Exception e#
29+
(runtime/log-error (str "Warning: " ~context " failed: " (.getMessage e#)))
30+
nil)))
2831

2932
(defn retrieve-page-access-token [id token version]
30-
(let [accounts (swallow-exceptions (request/get-accounts token :version version))
31-
page-token-from-accounts-list (if (some? accounts) (:access_token (first (filter #(= id (:id %)) accounts))))
32-
page-token-from-page-details (swallow-exceptions (request/get-page-token-via-page-details token id))
33+
(let [accounts (try-with-warning (str "fetching accounts list for page " id)
34+
(request/get-accounts token :version version))
35+
page-token-from-accounts-list (when (some? accounts)
36+
(:access_token (first (filter #(= id (:id %)) accounts))))
37+
page-token-from-page-details (when (nil? page-token-from-accounts-list)
38+
(try-with-warning (str "fetching page token via page details for " id)
39+
(request/get-page-token-via-page-details token id)))
3340
page-token (or page-token-from-accounts-list page-token-from-page-details)]
34-
(if (nil? page-token)
35-
(runtime/log-strings "Could not find page access token for" id ". Token from the configuration will be used instead.")
36-
(runtime/log-strings "Using page access token to retrieve data for" id))
41+
(cond
42+
(some? page-token)
43+
(runtime/log-strings "Using page access token to retrieve data for" id)
44+
(and (nil? accounts) (nil? page-token-from-page-details))
45+
(runtime/log-error (str "Page token failed for " id ": both /me/accounts and page details API failed. "
46+
"The user token will be used but may lack permissions for insights queries."))
47+
:else
48+
(runtime/log-strings "Could not find page access token for" id ". Token from the configuration will be used instead."))
3749
page-token))
3850

3951
(defn choose-token [id user-token version]

0 commit comments

Comments
 (0)